当前位置: 首页>>代码示例>>Golang>>正文


Golang bone.Mux类代码示例

本文整理汇总了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))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:8,代码来源:stats_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:10,代码来源:state_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:10,代码来源:hoverfly_mode_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:11,代码来源:middleware_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:18,代码来源:auth_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:16,代码来源:templates_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:16,代码来源:metadata_handler.go

示例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),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:6,代码来源:count_handler.go

示例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
}
开发者ID:martin-helmich,项目名称:servicegateway,代码行数:66,代码来源:graphical.go

示例10: RegisterRoutes

func (this *HealthHandler) RegisterRoutes(mux *bone.Mux, am *handlers.AuthHandler) {
	mux.Get("/api/health", negroni.New(
		negroni.HandlerFunc(this.Get),
	))
}
开发者ID:SpectoLabs,项目名称:hoverfly,代码行数:5,代码来源:health_handler.go


注:本文中的github.com/go-zoo/bone.Mux类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。