ing
This commit is contained in:
parent
ab5e366a2c
commit
36a4d42bb8
|
@ -27,17 +27,17 @@ type RESTServlet interface {
|
||||||
type RESTServlets struct {
|
type RESTServlets struct {
|
||||||
cswf.Servlets
|
cswf.Servlets
|
||||||
|
|
||||||
RESTRegistry crr.RESTRegistry
|
restRegistry crr.RESTRegistry
|
||||||
|
|
||||||
MethodMapping map[string]map[string]*MethodMapping
|
methodMapping map[string]map[string]*MethodMapping
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RESTServlets) Init(serverCtx server.ServerCtx) error {
|
func (s *RESTServlets) Init(serverCtx server.ServerCtx) error {
|
||||||
if err := s.Servlets.Init(serverCtx); nil != err {
|
if err := s.Servlets.Init(serverCtx); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if nil == s.MethodMapping {
|
if nil == s.methodMapping {
|
||||||
s.MethodMapping = make(map[string]map[string]*MethodMapping)
|
s.methodMapping = make(map[string]map[string]*MethodMapping)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -47,7 +47,7 @@ func (s *RESTServlets) Handle(servletCtx server.ServletCtx, ctx *fasthttp.Reques
|
||||||
method := string(ctx.Method())
|
method := string(ctx.Method())
|
||||||
path := string(ctx.Path())
|
path := string(ctx.Path())
|
||||||
|
|
||||||
es, ok := s.MethodMapping[method]
|
es, ok := s.methodMapping[method]
|
||||||
if !ok {
|
if !ok {
|
||||||
return csw.NewError(fasthttp.StatusNotFound, fmt.Errorf("Not Found for [%s]%s", method, path))
|
return csw.NewError(fasthttp.StatusNotFound, fmt.Errorf("Not Found for [%s]%s", method, path))
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func (s *RESTServlets) HandleGet(servletCtx server.ServletCtx, ctx *fasthttp.Req
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.RESTRegistry.Invoke(mapping.Method, params, servletCtx, ctx)
|
_, err := s.restRegistry.Invoke(mapping.Method, params, servletCtx, ctx)
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return csw.NewError(fasthttp.StatusInternalServerError, err)
|
return csw.NewError(fasthttp.StatusInternalServerError, err)
|
||||||
|
@ -109,7 +109,7 @@ func (s *RESTServlets) HandlePost(servletCtx server.ServletCtx, ctx *fasthttp.Re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.RESTRegistry.Invoke(mapping.Method, params, servletCtx, ctx)
|
_, err := s.restRegistry.Invoke(mapping.Method, params, servletCtx, ctx)
|
||||||
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return csw.NewError(fasthttp.StatusInternalServerError, err)
|
return csw.NewError(fasthttp.StatusInternalServerError, err)
|
||||||
|
@ -123,8 +123,8 @@ func (s *RESTServlets) RegisterRESTServices(services []interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.MethodMapping = make(map[string]map[string]*MethodMapping)
|
s.methodMapping = make(map[string]map[string]*MethodMapping)
|
||||||
s.RESTRegistry = crr.NewRESTRegistry()
|
s.restRegistry = crr.NewRESTRegistry()
|
||||||
|
|
||||||
LOOP:
|
LOOP:
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
|
@ -133,7 +133,7 @@ LOOP:
|
||||||
if nil == ta {
|
if nil == ta {
|
||||||
return fmt.Errorf("Service[%s] is not RESTService, use @RESTService", t.Elem().Name())
|
return fmt.Errorf("Service[%s] is not RESTService, use @RESTService", t.Elem().Name())
|
||||||
}
|
}
|
||||||
s.RESTRegistry.RegisterService(service, "")
|
s.restRegistry.RegisterService(service, "")
|
||||||
|
|
||||||
mas := cdr.GetMethodAnnotations(t, oca.RequestMappingAnnotationType)
|
mas := cdr.GetMethodAnnotations(t, oca.RequestMappingAnnotationType)
|
||||||
if nil == mas || 0 == len(mas) {
|
if nil == mas || 0 == len(mas) {
|
||||||
|
@ -142,10 +142,10 @@ LOOP:
|
||||||
|
|
||||||
for methodName, v := range mas {
|
for methodName, v := range mas {
|
||||||
ma := v.(*oca.RequestMappingAnnotation)
|
ma := v.(*oca.RequestMappingAnnotation)
|
||||||
mm, ok := s.MethodMapping[ma.Method]
|
mm, ok := s.methodMapping[ma.Method]
|
||||||
if !ok {
|
if !ok {
|
||||||
mm = make(map[string]*MethodMapping)
|
mm = make(map[string]*MethodMapping)
|
||||||
s.MethodMapping[ma.Method] = mm
|
s.methodMapping[ma.Method] = mm
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok = mm[ma.Entry]
|
_, ok = mm[ma.Entry]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user