本文整理匯總了Golang中github.com/gin-gonic/gin.Engine.Group方法的典型用法代碼示例。如果您正苦於以下問題:Golang Engine.Group方法的具體用法?Golang Engine.Group怎麽用?Golang Engine.Group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gin-gonic/gin.Engine
的用法示例。
在下文中一共展示了Engine.Group方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: prepareRoutes
func prepareRoutes(router *gin.Engine) {
// Web Resources
router.Static("/static", "web/dist")
// API Routes
api := router.Group("/api/v1")
admin := api.Group("/admin")
public := api.Group("/public")
registered := api.Group("/")
sameRegisteredUser := api.Group("/user")
prepareMiddleware(admin, public, registered, sameRegisteredUser)
admin.GET("/users", listUsers)
admin.GET("/places", listPlaces)
admin.POST("/places", createPlace)
admin.POST("/events", createEvent)
admin.PUT("/place/:placeId", updatePlace)
admin.PUT("/event/:eventId", updateEvent)
admin.DELETE("/event/:eventId", cancelEvent)
sameRegisteredUser.GET("/:userId", getUser)
sameRegisteredUser.PUT("/:userId", updateUser)
sameRegisteredUser.DELETE("/:userId", disableUser)
registered.POST("/buy/:seatId", buyTicket)
public.GET("/place/:placeId", getPlace)
public.GET("/events", listEvents)
public.GET("/event/:eventId", getEvent)
public.POST("/users", createUser) // TODO Checar, me huele raro......
public.POST("/login", loginUser)
}
示例2: mapRoutes
func mapRoutes(router *gin.Engine) {
router.Use(cors.Middleware(cors.Config{
Origins: "http://openbonfires.github.io, https://openbonfires.github.io",
}))
//mapped router for authenticated urls only
api := router.Group("/api")
api.GET("/randomquote", func(c *gin.Context) {
res, err := http.Get("http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en")
if err == nil {
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err == nil {
c.String(http.StatusOK, string(body))
} else {
c.String(http.StatusInternalServerError, "Unable to read the response date from the random quotes API.")
}
} else {
c.String(http.StatusInternalServerError, "Unable to communicate with random quotes API.")
}
})
//All other requests
router.Use(func(c *gin.Context) {
c.String(http.StatusNotFound, "Requested url does not exist")
c.Abort()
})
}
示例3: Init
func Init(router *gin.Engine, DB *db.Session, fn func() gin.HandlerFunc) {
// Simple group: v1
api := &API{DB}
v1 := router.Group("/v1")
{
v1.Use(fn())
policies := v1.Group("policies")
{
policies.POST("/", api.createPolicy)
policies.GET("/", api.getPolicies)
policies.DELETE("/", api.deletePolicies)
policies.DELETE("/:id", api.deletePolicy)
policies.PUT("/:id", api.updatePolicy)
}
res := v1.Group("resources")
{
res.POST("/", api.createResource)
res.GET("/:type", api.getResources)
//res.GET("/:type/:id", api.getResources)
res.DELETE("/", api.deleteResources)
res.DELETE("/:id", api.deleteResource)
res.PUT("/:id", api.updateResource)
}
}
}
示例4: SetupRoutes
func SetupRoutes(router *gin.Engine) {
router.GET("/", GetHome)
router.GET("/static/*path", GetAsset)
api := router.Group("/api")
{
SetupMiddlewares(api)
api.GET("/info", GetInfo)
api.POST("/connect", Connect)
api.GET("/databases", GetDatabases)
api.GET("/connection", GetConnectionInfo)
api.GET("/activity", GetActivity)
api.GET("/schemas", GetSchemas)
api.GET("/tables", GetTables)
api.GET("/tables/:table", GetTable)
api.GET("/tables/:table/rows", GetTableRows)
api.GET("/tables/:table/info", GetTableInfo)
api.GET("/tables/:table/indexes", GetTableIndexes)
api.GET("/query", RunQuery)
api.POST("/query", RunQuery)
api.GET("/explain", ExplainQuery)
api.POST("/explain", ExplainQuery)
api.GET("/history", GetHistory)
api.GET("/bookmarks", GetBookmarks)
}
}
示例5: setupRoutes
// setupRoutes is an internal method where we setup application routes
func setupRoutes(r *gin.Engine) {
// TODO: home route "/" is not yet defined.
// r.GET("/", ...)
// static files served by application
r.Static("/static", "./static")
// auth urls for the login form and logout url
r.GET("/login", auth.Login)
r.POST("/login", auth.Login)
r.GET("/logout", auth.Logout)
// sessionResource is a special auth api resource, with POST and DELETE
// endpoints used for logging a user in or out.
sessionResource := r.Group("/api/session")
{
sessionResource.POST("", auth.LoginAPI)
sessionResource.DELETE("", auth.LogoutAPI)
}
// admin urls
adminRoutes := r.Group("/admin", auth.LoginRequired())
{
adminRoutes.GET("", admin.Admin)
adminRoutes.GET("/json", admin.JSONTest)
}
}
示例6: InitRoutesTopics
// InitRoutesTopics initialized routes for Topics Controller
func InitRoutesTopics(router *gin.Engine) {
topicsCtrl := &controllers.TopicsController{}
g := router.Group("/")
g.Use(CheckPassword())
{
g.GET("/topics", topicsCtrl.List)
g.POST("/topic", topicsCtrl.Create)
g.DELETE("/topic/*topic", topicsCtrl.Delete)
g.GET("/topic/*topic", topicsCtrl.OneTopic)
g.PUT("/topic/add/parameter", topicsCtrl.AddParameter)
g.PUT("/topic/remove/parameter", topicsCtrl.RemoveParameter)
g.PUT("/topic/add/rouser", topicsCtrl.AddRoUser)
g.PUT("/topic/remove/rouser", topicsCtrl.RemoveRoUser)
g.PUT("/topic/add/rwuser", topicsCtrl.AddRwUser)
g.PUT("/topic/remove/rwuser", topicsCtrl.RemoveRwUser)
g.PUT("/topic/add/adminuser", topicsCtrl.AddAdminUser)
g.PUT("/topic/remove/adminuser", topicsCtrl.RemoveAdminUser)
g.PUT("/topic/add/rogroup", topicsCtrl.AddRoGroup)
g.PUT("/topic/remove/rogroup", topicsCtrl.RemoveRoGroup)
g.PUT("/topic/add/rwgroup", topicsCtrl.AddRwGroup)
g.PUT("/topic/remove/rwgroup", topicsCtrl.RemoveRwGroup)
g.PUT("/topic/add/admingroup", topicsCtrl.AddAdminGroup)
g.PUT("/topic/remove/admingroup", topicsCtrl.RemoveAdminGroup)
g.PUT("/topic/param", topicsCtrl.SetParam)
}
}
示例7: registerRoutes
func registerRoutes(server *gin.Engine) {
podRoute := server.Group("/pod")
{
podRoute.POST("/create", PodCreate)
podRoute.GET("/state/:pod", PodState)
}
}
示例8: Init
// Init initializes application routers.
func Init(g *gin.Engine) {
g.Use(middleware.UserFromToken())
// Home page.
g.GET("/", Home)
// Health check group.
h := g.Group("/h")
{
h.GET("/ping", health.Ping)
}
// User related group.
u := g.Group("/user")
{
usin := u.Group("/signin")
usin.Use(middleware.NotAuthenticated())
{
usin.POST("/:service", auth.SignIn)
usin.GET("/:service/complete", auth.SignInComplete)
}
urepos := u.Group("/repos")
urepos.Use(middleware.Authenticated())
{
urepos.GET("/:service", repos.ReposList)
urepos.PATCH("/:service", repos.ReposUpdate)
}
}
}
示例9: Register
func Register(r *gin.Engine) {
api(r.Group("/api"))
r.GET("/", showIndex)
r.GET("/h/:_", showIndex)
r.GET("/p/:_", showIndex)
}
示例10: initGreetings
// wire up the greetings routes
func initGreetings(e *gin.Engine, f engine.EngineFactory, endpoint string) {
greeter := &greeter{f.NewGreeter()}
g := e.Group(endpoint)
{
g.GET("", greeter.list)
g.POST("", greeter.add)
}
}
示例11: register
func (r *TurmaResource) register(router *gin.Engine) {
grupo := router.Group("/ges/v1/api")
grupo.GET("/turmas", r.obterTodas)
grupo.POST("/turmas", r.cadastrar)
grupo.PUT("/turmas/:id", r.alterar)
grupo.DELETE("/turmas/:id", r.excluir)
}
示例12: buildRoutes
func buildRoutes(r *gin.Engine) {
v1 := r.Group("/v1")
{
v1.GET(encryptPath, encryptContext())
v1.POST(encryptPath, newEncryptContext())
v1.GET(decryptPath, decryptContext())
v1.GET(echoPath, echoContext())
}
}
示例13: Register
// Register registers the route handlers for this controller
func (f *FrontController) Register(r *gin.Engine) {
front := r.Group("/")
{
front.GET("/", f.getIndex)
front.GET("/healthcheck", f.getHealthCheck)
}
r.NoRoute(f.getNotFound)
}
示例14: configApi
func configApi(engine *gin.Engine) {
api := engine.Group("/api")
{
api.GET("/", func(c *gin.Context) { c.Writer.WriteHeader(200) })
api.POST("/todos", NewTodo)
api.GET("/todos", ListTodos)
api.DELETE("/todos/:id", DeleteTodo)
api.PUT("/todos/:id", UpateTodo)
}
}
示例15: InitRoutesPresences
// InitRoutesPresences initialized routes for Presences Controller
func InitRoutesPresences(router *gin.Engine) {
presencesCtrl := &controllers.PresencesController{}
g := router.Group("/")
g.Use(CheckPassword())
{
// List Presences
g.GET("presences/*topic", presencesCtrl.List)
// Add a presence and get list
g.POST("presenceget/*topic", presencesCtrl.CreateAndGet)
}
}