本文整理汇总了Golang中github.com/go-zoo/bone.Mux类的典型用法代码示例。如果您正苦于以下问题:Golang Mux类的具体用法?Golang Mux怎么用?Golang Mux使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mux类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegisterRoutes
func (this *StatsHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/stats", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
// TODO: check auth for websocket connection
mux.Get("/api/statsws", http.HandlerFunc(this.GetWS))
}
示例2: RegisterRoutes
func (this *StateHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/state", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
mux.Post("/api/state", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Post),
))
}
示例3: RegisterRoutes
func (this *HoverflyModeHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/v2/hoverfly/mode", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
mux.Put("/api/v2/hoverfly/mode", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Put),
))
}
示例4: RegisterRoutes
func (this *MiddlewareHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/middleware", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Redirect),
))
mux.Post("/api/middleware", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Redirect),
))
}
示例5: RegisterRoutes
func (this *AuthHandler) RegisterRoutes(mux *bone.Mux) {
mux.Post("/api/token-auth", http.HandlerFunc(this.Login))
mux.Get("/api/refresh-token-auth", negroni.New(
negroni.HandlerFunc(this.RequireTokenAuthentication),
negroni.HandlerFunc(this.RefreshToken),
))
mux.Get("/api/logout", negroni.New(
negroni.HandlerFunc(this.RequireTokenAuthentication),
negroni.HandlerFunc(this.Logout),
))
mux.Get("/api/users", negroni.New(
negroni.HandlerFunc(this.RequireTokenAuthentication),
negroni.HandlerFunc(this.GetAllUsersHandler),
))
}
示例6: RegisterRoutes
func (this *TemplatesHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/templates", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
mux.Delete("/api/templates", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Delete),
))
mux.Post("/api/templates", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Post),
))
}
示例7: RegisterRoutes
func (this *MetadataHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/metadata", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
mux.Put("/api/metadata", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Put),
))
mux.Delete("/api/metadata", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Delete),
))
}
示例8: RegisterRoutes
func (this *CountHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/count", negroni.New(
negroni.HandlerFunc(am.RequireTokenAuthentication),
negroni.HandlerFunc(this.Get),
))
}
示例9: RegisterRoutes
func (a *GraphicalAuthDecorator) RegisterRoutes(mux *bone.Mux) error {
tmpl, err := template.ParseFiles(
a.uiDir+"/templates/login.html",
a.uiDir+"/templates/layout.html",
)
if err != nil {
return err
}
fileserver := http.FileServer(http.Dir(a.uiDir + "/static/"))
mux.Get("/_static/", http.StripPrefix("/_static/", fileserver))
mux.GetFunc(a.config.GraphicalConfig.LoginRoute, func(res http.ResponseWriter, req *http.Request) {
result := LoginResult{}
if len(req.URL.Query()["redirect"]) > 0 {
result.Redirect = req.URL.Query()["redirect"][0]
}
err := tmpl.ExecuteTemplate(res, "layout", &result)
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(err.Error()))
}
})
mux.PostFunc("/_gateway/authenticate", func(res http.ResponseWriter, req *http.Request) {
username := req.PostFormValue("username")
password := req.PostFormValue("password")
redirect := req.PostFormValue("redirect")
result := LoginResult{Redirect: redirect}
if username == "" {
result.Errors.UserEmpty = true
}
if password == "" {
result.Errors.PasswordEmpty = true
}
if result.HasErrors() {
tmpl.ExecuteTemplate(res, "layout", &result)
return
}
token, err := a.authHandler.Authenticate(username, password)
if err != nil {
result.Errors.InvalidCredentials = true
res.WriteHeader(http.StatusUnauthorized)
tmpl.ExecuteTemplate(res, "layout", &result)
return
}
a.authHandler.storage.WriteToken(res, token)
if redirect != "" {
res.Header().Set("Location", redirect)
res.WriteHeader(303)
res.Write([]byte("Successfully authenticated. Redirecting to original request."))
} else {
res.Write([]byte("Hello."))
}
})
return nil
}
示例10: RegisterRoutes
func (this *HealthHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
mux.Get("/api/health", negroni.New(
negroni.HandlerFunc(this.Get),
))
}