このライブラリは、学習の価値があります、
彼はより多くのスリップを書くように見えます
メインパッケージ のインポート( "FMT" "ログ" "ネット/ HTTP" // "時間" "github.com/codegangsta/negroni" "github.com/gorilla/context" ) http.ResponseWriter、R * HTTP wが承認FUNCを( .Request、次http.HandlerFunc){ トークン:= r.Header.Get( "X-AppToken") == "bXlVc2VybmFtZTpteVBhc3N3b3Jk" {トークンなら log.Printf( "システムを許可") context.Set(R、 "ユーザ」、 "シジューVarghese") 次の(W、R) }他{ http.Error(W "許可しない"、401)。 } } FUNC指数(W http.ResponseWriter、R * http.Request){ ユーザー: メインFUNC(){= context.Get(R、 "ユーザ") fmt.Fprintf(ユーザ、 "ようこそ!%s"は、W) } MUX:= http.NewServeMux() mux.HandleFunc( "/"、インデックス) N:= negroni.Classic() n.Use(negroni.HandlerFunc(承認)) n.UseHandler(MUX) n.Run( ": 8080" ) }