Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
542d4cec00 | |||
0ecd1da0dc | |||
0a8755ecb7 | |||
9c29d92d7f |
29
http.go
29
http.go
@@ -228,20 +228,29 @@ func (h *Server) NewHandler(handler interface{}, opts ...server.HandlerOption) s
|
||||
pth := &patHandler{mtype: mtype, name: name, rcvr: rcvr}
|
||||
hdlr.name = name
|
||||
|
||||
if err := hdlr.handlers.Insert([]string{md["Method"]}, md["Path"], pth); err != nil {
|
||||
h.opts.Logger.Errorf(h.opts.Context, "cant add handler for %s %s", md["Method"], md["Path"])
|
||||
}
|
||||
|
||||
methods := []string{md["Method"]}
|
||||
if h.registerCORS {
|
||||
h.opts.Logger.Infof(h.opts.Context, "register cors handler for http.MethodOptions %s /%s", hn, hn)
|
||||
if err := hdlr.handlers.Insert([]string{http.MethodOptions}, "/"+hn, pth); err != nil {
|
||||
h.opts.Logger.Errorf(h.opts.Context, "cant add rpc handler for http.MethodOptions %s /%s", hn, hn)
|
||||
}
|
||||
logger.Infof(h.opts.Context, "register cors handler for http.MethodOptions %s", md["Path"])
|
||||
methods = append(methods, http.MethodOptions)
|
||||
} else {
|
||||
logger.Infof(h.opts.Context, "not register cors handler for http.MethodOptions %s", md["Path"])
|
||||
}
|
||||
|
||||
if err := hdlr.handlers.Insert(methods, md["Path"], pth); err != nil {
|
||||
logger.Errorf(h.opts.Context, "cant add handler for %v %s", methods, md["Path"])
|
||||
}
|
||||
|
||||
logger.Infof(h.opts.Context, fmt.Sprintf("try to detect rpc handlers usage %v", h.registerRPC))
|
||||
if h.registerRPC {
|
||||
h.opts.Logger.Infof(h.opts.Context, "register rpc handler for http.MethodPost %s /%s", hn, hn)
|
||||
if err := hdlr.handlers.Insert([]string{http.MethodPost}, "/"+hn, pth); err != nil {
|
||||
methods := []string{http.MethodPost}
|
||||
if h.registerCORS {
|
||||
logger.Infof(h.opts.Context, "register cors handler for %v %s", methods, "/"+hn)
|
||||
methods = append(methods, http.MethodOptions)
|
||||
} else {
|
||||
logger.Infof(h.opts.Context, "not register cors handler for %v %s", methods, "/"+hn)
|
||||
}
|
||||
|
||||
if err := hdlr.handlers.Insert(methods, "/"+hn, pth); err != nil {
|
||||
h.opts.Logger.Errorf(h.opts.Context, "cant add rpc handler for http.MethodPost %s /%s", hn, hn)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user