API docs
This commit is contained in:
50
vendor/github.com/go-chi/docgen/util.go
generated
vendored
Normal file
50
vendor/github.com/go-chi/docgen/util.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
package docgen
|
||||
|
||||
import (
|
||||
"go/build"
|
||||
"os"
|
||||
)
|
||||
|
||||
func copyDocRouter(dr DocRouter) DocRouter {
|
||||
var cloneRouter func(dr DocRouter) DocRouter
|
||||
var cloneRoutes func(drt DocRoutes) DocRoutes
|
||||
|
||||
cloneRoutes = func(drts DocRoutes) DocRoutes {
|
||||
rts := DocRoutes{}
|
||||
|
||||
for pat, drt := range drts {
|
||||
rt := DocRoute{Pattern: drt.Pattern}
|
||||
if len(drt.Handlers) > 0 {
|
||||
rt.Handlers = DocHandlers{}
|
||||
for meth, dh := range drt.Handlers {
|
||||
rt.Handlers[meth] = dh
|
||||
}
|
||||
}
|
||||
if drt.Router != nil {
|
||||
rr := cloneRouter(*drt.Router)
|
||||
rt.Router = &rr
|
||||
}
|
||||
rts[pat] = rt
|
||||
}
|
||||
|
||||
return rts
|
||||
}
|
||||
|
||||
cloneRouter = func(dr DocRouter) DocRouter {
|
||||
cr := DocRouter{}
|
||||
cr.Middlewares = make([]DocMiddleware, len(dr.Middlewares))
|
||||
copy(cr.Middlewares, dr.Middlewares)
|
||||
cr.Routes = cloneRoutes(dr.Routes)
|
||||
return cr
|
||||
}
|
||||
|
||||
return cloneRouter(dr)
|
||||
}
|
||||
|
||||
func getGoPath() string {
|
||||
goPath := os.Getenv("GOPATH")
|
||||
if goPath == "" {
|
||||
goPath = build.Default.GOPATH
|
||||
}
|
||||
return goPath
|
||||
}
|
Reference in New Issue
Block a user