mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
feat: support sse in api files (#5074)
Signed-off-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
@@ -40,7 +40,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
`
|
||||
routesAdditionTemplate = `
|
||||
server.AddRoutes(
|
||||
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}} {{.timeout}} {{.maxBytes}}
|
||||
{{.routes}} {{.jwt}}{{.signature}} {{.prefix}} {{.timeout}} {{.maxBytes}} {{.sse}}
|
||||
)
|
||||
`
|
||||
timeoutThreshold = time.Millisecond
|
||||
@@ -63,6 +63,7 @@ type (
|
||||
routes []route
|
||||
jwtEnabled bool
|
||||
signatureEnabled bool
|
||||
sseEnabled bool
|
||||
authName string
|
||||
timeout string
|
||||
middlewares []string
|
||||
@@ -123,10 +124,17 @@ func genRoutes(dir, rootPkg string, cfg *config.Config, api *spec.ApiSpec) error
|
||||
if len(g.jwtTrans) > 0 {
|
||||
jwt = jwt + fmt.Sprintf("\n rest.WithJwtTransition(serverCtx.Config.%s.PrevSecret,serverCtx.Config.%s.Secret),", g.jwtTrans, g.jwtTrans)
|
||||
}
|
||||
|
||||
var signature, prefix string
|
||||
if g.signatureEnabled {
|
||||
signature = "\n rest.WithSignature(serverCtx.Config.Signature),"
|
||||
}
|
||||
|
||||
var sse string
|
||||
if g.sseEnabled {
|
||||
sse = "\n rest.WithSSE(),"
|
||||
}
|
||||
|
||||
if len(g.prefix) > 0 {
|
||||
prefix = fmt.Sprintf(`
|
||||
rest.WithPrefix("%s"),`, g.prefix)
|
||||
@@ -172,6 +180,7 @@ rest.WithPrefix("%s"),`, g.prefix)
|
||||
"routes": routes,
|
||||
"jwt": jwt,
|
||||
"signature": signature,
|
||||
"sse": sse,
|
||||
"prefix": prefix,
|
||||
"timeout": timeout,
|
||||
"maxBytes": maxBytes,
|
||||
@@ -281,6 +290,10 @@ func getRoutes(api *spec.ApiSpec) ([]group, error) {
|
||||
if signature == "true" {
|
||||
groupedRoutes.signatureEnabled = true
|
||||
}
|
||||
sse := g.GetAnnotation("sse")
|
||||
if sse == "true" {
|
||||
groupedRoutes.sseEnabled = true
|
||||
}
|
||||
middleware := g.GetAnnotation("middleware")
|
||||
if len(middleware) > 0 {
|
||||
groupedRoutes.middlewares = append(groupedRoutes.middlewares,
|
||||
|
||||
Reference in New Issue
Block a user