combine native and micro http handlers

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2022-01-23 02:00:15 +03:00
parent 6714e48f4f
commit 31e996fc2e
3 changed files with 15 additions and 4 deletions

11
http.go
View File

@@ -22,6 +22,8 @@ import (
"golang.org/x/net/netutil"
)
var _ server.Server = &httpServer{}
type httpServer struct {
hd server.Handler
rsvc *register.Service
@@ -448,12 +450,15 @@ func (h *httpServer) Start() error {
}
}
if handler == nil && h.hd == nil {
switch {
case handler == nil && h.hd == nil:
handler = h
} else if handler == nil && h.hd != nil {
case handler == nil && h.hd != nil:
if hdlr, ok := h.hd.Handler().(http.Handler); ok {
handler = hdlr
}
case len(h.handlers) > 0 && h.hd != nil:
handler = h
}
if handler == nil {
@@ -585,7 +590,7 @@ func (h *httpServer) Name() string {
return h.opts.Name
}
func NewServer(opts ...server.Option) server.Server {
func NewServer(opts ...server.Option) *httpServer {
options := server.NewOptions(opts...)
return &httpServer{
opts: options,