tips 各种小记录
hide win
go build -ldflags "-H windowsgui"
go build -ldflags "-s -w"
-s
去掉符号表,然后 panic
的时候 stack trace
就没有任何文件名/行号信息了。
-w
去掉 DWARF
调试信息,得到的程序就不能用 gdb
调试。
查看汇编
go tool compile -S main.go
static file
// 根访问
http.Handle("/", http.FileServer(http.Dir(".")))
// 指定 路径访问
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
cookie
http.HandleFunc("/one", func(w http.ResponseWriter, r *http.Request) {
cookie := &http.Cookie{Name: "cookie", Value: "zxysilent", Path: "/", HttpOnly: true,MaxAge: 7200}
http.SetCookie(w, cookie)
})
http.HandleFunc("/two", func(w http.ResponseWriter, r *http.Request) {
cookie, _ := r.Cookie("cookie")
w.Write([]byte(cookie.String()))
})
跨域
w.Header().Set(`Access-Control-Allow-Origin`, `*`)
中间件
1
http.Handle(`/`, mid(http.HandlerFunc(fn)))
func mid(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
//中间件的逻辑
w.Header().Set("Content-Type", "application/json")
w.Header().Set(`Access-Control-Allow-Origin`, `*`)
next.ServeHTTP(w, r)
})
}
2
http.HandleFunc(`/`, mid(fn))
func mid(next http.HandlerFunc) http.HandlerFunc{
return func(w http.ResponseWriter, r *http.Request) {
//中间件的逻辑
w.Header().Set("Content-Type", "application/json")
w.Header().Set(`Access-Control-Allow-Origin`, `*`)
next.ServeHTTP(w, r)
}
}
npm
prefix = D:\Program Files\nodejs\node_global
cache = D:\Program Files\nodejs\node_cache
cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
// --history-api-fallback 解决本地开发 vue-router-history模式 404 错误
"scripts": {
"dev": "webpack-dev-server --content-base ./ --open --inline --hot --port=82 --history-api-fallback --compress --config build/webpack.dev.config.js",
"build": "webpack --progress --hide-modules --config build/webpack.prod.config.js"
},
install git
sudo apt-get install git git-core git-doc
node
npm install --registry=https://registry.npm.taobao.org
prod
npm run webpack.build.production