Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: server/auth/info/info.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/auth/handlers.go ('k') | server/auth/info/info_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/info/info.go
diff --git a/server/auth/info/info.go b/server/auth/info/info.go
index f03abdcc8ba4bbf2794b519ff0ec56ad8260033e..b163f230e8785db29197b662cd8ce180a23cea61 100644
--- a/server/auth/info/info.go
+++ b/server/auth/info/info.go
@@ -6,26 +6,25 @@
//
// This endpoint is used by luci services to advertise service account names
// they use (among other things).
package info
import (
"encoding/json"
"net/http"
"time"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"github.com/luci/luci-go/server/auth/internal"
- "github.com/luci/luci-go/server/middleware"
"github.com/luci/luci-go/server/proccache"
+ "github.com/luci/luci-go/server/router"
)
// ServiceInfo describes JSON format of /auth/api/v1/server/info response.
type ServiceInfo struct {
AppID string `json:"app_id,omitempty"`
AppRuntime string `json:"app_runtime,omitempty"`
AppRuntimeVersion string `json:"app_runtime_version,omitempty"`
AppVersion string `json:"app_version,omitempty"`
ServiceAccountName string `json:"service_account_name,omitempty"`
}
@@ -49,29 +48,29 @@ func FetchServiceInfo(c context.Context, serviceURL string) (*ServiceInfo, error
if err != nil {
return nil, err
}
return info.(*ServiceInfo), nil
}
// ServiceInfoCallback is called by /auth/api/v1/server/info handler.
type ServiceInfoCallback func(context.Context) (ServiceInfo, error)
// InstallHandlers installs handler that serves info provided by the callback.
-func InstallHandlers(r *httprouter.Router, base middleware.Base, cb ServiceInfoCallback) {
- handler := func(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func InstallHandlers(r *router.Router, base router.MiddlewareChain, cb ServiceInfoCallback) {
+ handler := func(c *router.Context) {
var response struct {
ServiceInfo
Error string `json:"error,omitempty"`
}
- info, err := cb(c)
- w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ info, err := cb(c.Context)
+ c.Writer.Header().Set("Content-Type", "application/json; charset=utf-8")
if err != nil {
- w.WriteHeader(http.StatusInternalServerError)
+ c.Writer.WriteHeader(http.StatusInternalServerError)
response.Error = err.Error()
} else {
- w.WriteHeader(http.StatusOK)
+ c.Writer.WriteHeader(http.StatusOK)
response.ServiceInfo = info
}
- json.NewEncoder(w).Encode(response)
+ json.NewEncoder(c.Writer).Encode(response)
}
- r.GET("/auth/api/v1/server/info", base(handler))
+ r.GET("/auth/api/v1/server/info", base, handler)
}
« no previous file with comments | « server/auth/handlers.go ('k') | server/auth/info/info_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698