|
|
@ -33,7 +33,7 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
|
|
|
|
`
|
|
|
|
`
|
|
|
|
routesAdditionTemplate = `
|
|
|
|
routesAdditionTemplate = `
|
|
|
|
engine.AddRoutes(
|
|
|
|
engine.AddRoutes(
|
|
|
|
{{.routes}} {{.jwt}}{{.signature}}
|
|
|
|
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
`
|
|
|
|
`
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -54,6 +54,7 @@ type (
|
|
|
|
signatureEnabled bool
|
|
|
|
signatureEnabled bool
|
|
|
|
authName string
|
|
|
|
authName string
|
|
|
|
middlewares []string
|
|
|
|
middlewares []string
|
|
|
|
|
|
|
|
prefix string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
route struct {
|
|
|
|
route struct {
|
|
|
|
method string
|
|
|
|
method string
|
|
|
@ -87,10 +88,14 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
|
|
|
|
if g.jwtEnabled {
|
|
|
|
if g.jwtEnabled {
|
|
|
|
jwt = fmt.Sprintf("\n rest.WithJwt(serverCtx.Config.%s.AccessSecret),", g.authName)
|
|
|
|
jwt = fmt.Sprintf("\n rest.WithJwt(serverCtx.Config.%s.AccessSecret),", g.authName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var signature string
|
|
|
|
var signature, prefix string
|
|
|
|
if g.signatureEnabled {
|
|
|
|
if g.signatureEnabled {
|
|
|
|
signature = "\n rest.WithSignature(serverCtx.Config.Signature),"
|
|
|
|
signature = "\n rest.WithSignature(serverCtx.Config.Signature),"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(g.prefix) > 0 {
|
|
|
|
|
|
|
|
prefix = fmt.Sprintf(`
|
|
|
|
|
|
|
|
rest.WithPrefix("%s"),`, g.prefix)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var routes string
|
|
|
|
var routes string
|
|
|
|
if len(g.middlewares) > 0 {
|
|
|
|
if len(g.middlewares) > 0 {
|
|
|
@ -111,6 +116,7 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
|
|
|
|
"routes": routes,
|
|
|
|
"routes": routes,
|
|
|
|
"jwt": jwt,
|
|
|
|
"jwt": jwt,
|
|
|
|
"signature": signature,
|
|
|
|
"signature": signature,
|
|
|
|
|
|
|
|
"prefix": prefix,
|
|
|
|
}); err != nil {
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -200,6 +206,11 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
|
|
|
|
groupedRoutes.middlewares = append(groupedRoutes.middlewares,
|
|
|
|
groupedRoutes.middlewares = append(groupedRoutes.middlewares,
|
|
|
|
strings.Split(middleware, ",")...)
|
|
|
|
strings.Split(middleware, ",")...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prefix := g.GetAnnotation(spec.RoutePrefixKey)
|
|
|
|
|
|
|
|
prefix = strings.TrimSpace(prefix)
|
|
|
|
|
|
|
|
prefix = strings.ReplaceAll(prefix, `"`, "")
|
|
|
|
|
|
|
|
prefix = path.Join("/", prefix)
|
|
|
|
|
|
|
|
groupedRoutes.prefix = prefix
|
|
|
|
routes = append(routes, groupedRoutes)
|
|
|
|
routes = append(routes, groupedRoutes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|