Skip to content

Commit 7ff1086

Browse files
committed
添加handler Name
1 parent 3da4b50 commit 7ff1086

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# mcube
2+
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/infraboard/mcube)](https://goreportcard.com/report/github.com/infraboard/mcube)
4+
[![Release](https://img.shields.io/github/release/infraboard/mcube.svg?style=flat-square)](https://github.com/infraboard/mcube/releases)
5+
26
微服务工具箱, 构建微服务中使用的工具集
37

48
+ http框架: 用于构建领域服务的路由框架, 基于httprouter进行封装

http/router/httprouter/httprouter.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ func (r *httpRouter) Use(m router.Middleware) {
5151
func (r *httpRouter) AddProtected(method, path string, h http.HandlerFunc) {
5252
e := &entry{
5353
Entry: &router.Entry{
54-
Method: method,
55-
Path: path,
56-
Protected: true,
57-
Labels: map[string]string{},
54+
Method: method,
55+
Path: path,
56+
FunctionName: router.GetHandlerFuncName(h),
57+
Protected: true,
58+
Labels: map[string]string{},
5859
},
5960
h: h,
6061
}
@@ -64,9 +65,11 @@ func (r *httpRouter) AddProtected(method, path string, h http.HandlerFunc) {
6465
func (r *httpRouter) AddPublict(method, path string, h http.HandlerFunc) {
6566
e := &entry{
6667
Entry: &router.Entry{
67-
Method: method,
68-
Path: path,
69-
Protected: false,
68+
Method: method,
69+
Path: path,
70+
FunctionName: router.GetHandlerFuncName(h),
71+
Protected: false,
72+
Labels: map[string]string{},
7073
},
7174
h: h,
7275
}

http/router/httprouter/subrouter.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ func (r *subRouter) With(m ...router.Middleware) router.SubRouter {
4242
func (r *subRouter) AddProtected(method, path string, h http.HandlerFunc) {
4343
e := &entry{
4444
Entry: &router.Entry{
45-
Resource: r.resourceName,
46-
Method: method,
47-
Path: path,
48-
Labels: map[string]string{},
45+
Resource: r.resourceName,
46+
Method: method,
47+
Path: path,
48+
FunctionName: router.GetHandlerFuncName(h),
49+
Labels: map[string]string{},
4950
},
5051
needAuth: true,
5152
h: h,
@@ -57,10 +58,11 @@ func (r *subRouter) AddProtected(method, path string, h http.HandlerFunc) {
5758
func (r *subRouter) AddPublict(method, path string, h http.HandlerFunc) {
5859
e := &entry{
5960
Entry: &router.Entry{
60-
Resource: r.resourceName,
61-
Method: method,
62-
Path: path,
63-
Labels: map[string]string{},
61+
Resource: r.resourceName,
62+
Method: method,
63+
Path: path,
64+
FunctionName: router.GetHandlerFuncName(h),
65+
Labels: map[string]string{},
6466
},
6567
needAuth: false,
6668
h: h,

http/router/router.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88

99
// Entry 路由条目
1010
type Entry struct {
11-
Path string `json:"path,omitempty"`
12-
Method string `json:"method,omitempty"`
13-
Resource string `json:"resource,omitempty"`
14-
Protected bool `json:"protected"`
15-
Labels map[string]string `json:"labels,omitempty"`
11+
Path string `json:"path,omitempty"`
12+
Method string `json:"method,omitempty"`
13+
FunctionName string `json:"function_name,omitempty"`
14+
Resource string `json:"resource,omitempty"`
15+
Protected bool `json:"protected,omitempty"`
16+
Labels map[string]string `json:"labels,omitempty"`
1617
}
1718

1819
// Router 路由
File renamed without changes.

0 commit comments

Comments
 (0)