Answer the question
In order to leave comments, you need to log in
GIN: is it possible to nest a router in a router?
In all examples, the routers are in the same place, I did not find any attachments anywhere.
r := gin.New()
main := r.Group("/main", midl())
main.Get("/get", mainPkg.get)
another := r.Group("/another", midl())
//и т.д.
r := gin.New()
main := r.Group("/main", here_imported_route.Route)
package here_imported_route
Router := gin.New()
Router.Use(midl())
Router.Get("/test", hello)
Answer the question
In order to leave comments, you need to log in
В главном роутинге что-то вроде
package main
import (
"path_to_pkg/pkg"
"github.com/gin-gonic/gin"
)
var r *gin.Engine
func init() {
r = gin.New()
pkg.Concon(r.Group("/pkg"))
}
func main() {
r.Run(":8080")
}
package pkg
import "github.com/gin-gonic/gin"
func Concon(g *gin.RouterGroup) {
g.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
}
Просто соблюдайте входные и выходные параметры. Возвращать функции с нужным перечнем входных и выходных параметров тоже можно. Остальное дело техники.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question