跳至主要内容

go ServeFile




package main

import (
 "fmt"
 "net/http"
)

func main() {

 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "sublime_text.tar.bz2"))
  w.Header().Add("Content-Type", "application/octet-stream")
  http.ServeFile(w, r, "/home/steven/sublime_text.tar.bz2")
 })

 err := http.ListenAndServe(":8090", nil)
 if err != nil {
  fmt.Println(err)
 }
}

评论

此博客中的热门博文

android hide actionbar

public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }

go url encoding

func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits. func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.