Skip to content

Commit

Permalink
some optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
wubin1989 committed Jan 9, 2024
1 parent 04514a1 commit db5d1bf
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/internal/svc/codegen/http2grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var appendHttp2GrpcTmpl = `
}
{{- end }}
{{- end }}
_writer.Header().Set("Content-Type", "application/json; charset=UTF-8")
{{- if eq (len $m.Results) 1 }}
if _err := json.NewEncoder(_writer).Encode(struct {}{}); _err != nil {
rest.HandleInternalServerError(_err)
Expand Down
1 change: 1 addition & 0 deletions cmd/internal/svc/codegen/httphandlerimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ var appendHttpHandlerImplTmpl = `
{{- end }}
{{- end }}
{{- if not $done }}
_writer.Header().Set("Content-Type", "application/json; charset=UTF-8")
if _err := json.NewEncoder(_writer).Encode(struct {
{{- range $r := $m.Results }}
{{- if ne $r.Type "error" }}
Expand Down
1 change: 0 additions & 1 deletion framework/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ type gddConfig struct {
EnableResponseGzip bool `default:"true" split_words:"true"`
LogReqEnable bool `default:"false" split_words:"true"`
ManageEnable bool `default:"true" split_words:"true"`
FallbackContenttype string `default:"application/json; charset=UTF-8" split_words:"true"`
Grpc struct {
Port string `default:"50051"`
}
Expand Down
5 changes: 4 additions & 1 deletion framework/rest/httprouter/routegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (r *RouteGroup) DELETE(path string, handle Handle) {
}

func (r *RouteGroup) subPath(path string) string {
validatePath(path)
result := r.p + path
if stringutils.IsEmpty(result) {
return "/"
}
return r.p + path
}
13 changes: 0 additions & 13 deletions framework/rest/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
Tracing = tracing
Metrics = metrics
Log = log
FallbackContentType = fallbackContentType
BasicAuth = basicAuth
Recovery = recovery
)
Expand Down Expand Up @@ -191,18 +190,6 @@ func rest(inner http.Handler) http.Handler {
})
}

// fallbackContentType set fallback response Content-Type to contentType
func fallbackContentType(contentType string) func(inner http.Handler) http.Handler {
return func(inner http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if stringutils.IsEmpty(w.Header().Get("Content-Type")) {
w.Header().Set("Content-Type", contentType)
}
inner.ServeHTTP(w, r)
})
}
}

// basicAuth adds http basic auth validation
func basicAuth() func(inner http.Handler) http.Handler {
username := config.DefaultGddManageUser
Expand Down
1 change: 0 additions & 1 deletion framework/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func NewRestServerWithOptions(options ...ServerOption) *RestServer {
srv.middlewares = append(srv.middlewares,
requestid.RequestIDHandler,
handlers.ProxyHeaders,
fallbackContentType(config.GddConfig.FallbackContenttype),
)
return srv
}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const Release = "v2.2.6"
const Release = "v2.2.7"

0 comments on commit db5d1bf

Please sign in to comment.