Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const prefixKey = "prefix"
|
||||
const groupKey = "group"
|
||||
|
||||
// Api describes syntax for api
|
||||
type Api struct {
|
||||
@@ -52,12 +53,16 @@ func (v *ApiVisitor) acceptService(root, final *Api) {
|
||||
}
|
||||
v.duplicateServerItemCheck(service)
|
||||
|
||||
var prefix string
|
||||
var prefix, group string
|
||||
if service.AtServer != nil {
|
||||
p := service.AtServer.Kv.Get(prefixKey)
|
||||
if p != nil {
|
||||
prefix = p.Text()
|
||||
}
|
||||
g := service.AtServer.Kv.Get(groupKey)
|
||||
if g != nil {
|
||||
group = g.Text()
|
||||
}
|
||||
}
|
||||
for _, route := range service.ServiceApi.ServiceRoute {
|
||||
uniqueRoute := fmt.Sprintf("%s %s", route.Route.Method.Text(), path.Join(prefix, route.Route.Path.Text()))
|
||||
@@ -92,10 +97,14 @@ func (v *ApiVisitor) acceptService(root, final *Api) {
|
||||
v.panic(handlerExpr, "mismatched handler")
|
||||
}
|
||||
|
||||
if _, ok := final.handlerM[handlerExpr.Text()]; ok {
|
||||
handlerKey := handlerExpr.Text()
|
||||
if len(group) > 0 {
|
||||
handlerKey = fmt.Sprintf("%s/%s", group, handlerExpr.Text())
|
||||
}
|
||||
if _, ok := final.handlerM[handlerKey]; ok {
|
||||
v.panic(handlerExpr, fmt.Sprintf("duplicate handler '%s'", handlerExpr.Text()))
|
||||
}
|
||||
final.handlerM[handlerExpr.Text()] = Holder
|
||||
final.handlerM[handlerKey] = Holder
|
||||
}
|
||||
final.Service = append(final.Service, service)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user