|
|
@@ -3,6 +3,8 @@ package handler
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
+ http2 "net/http"
|
|
|
+
|
|
|
"git.ikuban.com/server/kratos-utils/v2/transport/middleware"
|
|
|
ku_annotations "git.ikuban.com/server/kubanapis/kuban/api/annotations"
|
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
|
|
@@ -31,9 +33,8 @@ func RegisterRoute(s *http.Server, srv any, svcDesc grpc.ServiceDesc) {
|
|
|
if !option.GenHttp {
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
// 注册http接口
|
|
|
- r.POST(option.Path, unaryHandler(srv, md, option))
|
|
|
+ r.Handle(option.Method, option.Path, unaryHandler(srv, md, option))
|
|
|
}
|
|
|
|
|
|
// 注册流式方法handler
|
|
|
@@ -97,11 +98,24 @@ func GetOptionByServiceDescriptor(sd *desc.ServiceDescriptor, serviceName, metho
|
|
|
switch httpRule := rule.GetPattern().(type) {
|
|
|
case *annotations.HttpRule_Post:
|
|
|
option.Path = httpRule.Post
|
|
|
+ option.Method = http2.MethodPost
|
|
|
+ case *annotations.HttpRule_Get:
|
|
|
+ option.Path = httpRule.Get
|
|
|
+ option.Method = http2.MethodGet
|
|
|
+ case *annotations.HttpRule_Delete:
|
|
|
+ option.Path = httpRule.Delete
|
|
|
+ option.Method = http2.MethodDelete
|
|
|
+ case *annotations.HttpRule_Put:
|
|
|
+ option.Path = httpRule.Put
|
|
|
+ option.Method = http2.MethodPut
|
|
|
}
|
|
|
}
|
|
|
if option.Path == "" {
|
|
|
option.Path = fmt.Sprintf("/%s/%s", serviceName, methodName)
|
|
|
}
|
|
|
+ if option.Method == "" {
|
|
|
+ option.Method = http2.MethodPost
|
|
|
+ }
|
|
|
|
|
|
return option
|
|
|
}
|