lxg пре 4 година
родитељ
комит
9dc1bd2de6
3 измењених фајлова са 10 додато и 9 уклоњено
  1. 0 1
      .idea/workspace.xml
  2. 4 4
      micro.go
  3. 6 4
      service.go

+ 0 - 1
.idea/workspace.xml

@@ -4,7 +4,6 @@
     <list default="true" id="cd58867b-089e-4508-9033-393b8939261c" name="Default Changelist" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/micro.go" beforeDir="false" afterPath="$PROJECT_DIR$/micro.go" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/options.go" beforeDir="false" afterPath="$PROJECT_DIR$/options.go" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/service.go" beforeDir="false" afterPath="$PROJECT_DIR$/service.go" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />

+ 4 - 4
micro.go

@@ -9,16 +9,16 @@ type (
 	}
 
 	HandleOptions struct {
-		HttpMethod  string
-		DisableRpc  bool
-		DisableHttp bool
+		DisableRpc  bool   //禁用RPC功能
+		DisableHttp bool   //禁用HTTP功能
+		HttpPath    string //重定向HTTP路由
+		HttpMethod  string //HTTP路径
 	}
 
 	HandleOption func(o *HandleOptions)
 
 	HandleFunc func(ctx Context) (err error)
 
-
 	Application interface {
 		Handle(method string, cb HandleFunc, opts ...HandleOption)                     //注册一个处理器
 		CreateRequest(name, method string, body interface{}) (req *Request, err error) //创建一个rpc请求

+ 6 - 4
service.go

@@ -70,11 +70,13 @@ func (svr *Service) Handle(method string, cb HandleFunc, opts ...HandleOption) {
 	}
 	//HTTP处理
 	if svr.opts.EnableHttp && !opt.DisableHttp {
-		path := strings.ReplaceAll(method, ".", "/")
-		if path[0] != '/' {
-			path = "/" + path
+		if opt.HttpPath == "" {
+			opt.HttpPath = strings.ReplaceAll(method, ".", "/")
 		}
-		svr.httpSvr.Handle(opt.HttpMethod, path, func(ctx *http.Context) (err error) {
+		if opt.HttpPath[0] != '/' {
+			opt.HttpPath = "/" + opt.HttpPath
+		}
+		svr.httpSvr.Handle(opt.HttpMethod, opt.HttpPath, func(ctx *http.Context) (err error) {
 			return cb(ctx)
 		})
 	}