feat: add http server log

This commit is contained in:
miaolz123 2018-08-09 18:31:22 +08:00 committed by Vasiliy Tolstov
parent 6184752b27
commit 24f8e6b137

16
http.go
View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"sync" "sync"
"github.com/micro/go-log"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
@ -14,9 +15,10 @@ import (
type httpServer struct { type httpServer struct {
sync.Mutex sync.Mutex
opts server.Options opts server.Options
hd server.Handler hd server.Handler
exit chan chan error exit chan chan error
registerOnce sync.Once
} }
func init() { func init() {
@ -106,6 +108,10 @@ func (h *httpServer) Register() error {
registry.RegisterTTL(opts.RegisterTTL), registry.RegisterTTL(opts.RegisterTTL),
} }
h.registerOnce.Do(func() {
log.Logf("Registering node: %s", opts.Name+"-"+opts.Id)
})
return opts.Registry.Register(service, rOpts...) return opts.Registry.Register(service, rOpts...)
} }
@ -114,6 +120,8 @@ func (h *httpServer) Deregister() error {
opts := h.opts opts := h.opts
h.Unlock() h.Unlock()
log.Logf("Deregistering node: %s", opts.Name+"-"+opts.Id)
service := serviceDef(opts) service := serviceDef(opts)
return opts.Registry.Deregister(service) return opts.Registry.Deregister(service)
} }
@ -129,6 +137,8 @@ func (h *httpServer) Start() error {
return err return err
} }
log.Logf("Listening on %s", ln.Addr().String())
h.Lock() h.Lock()
h.opts.Address = ln.Addr().String() h.opts.Address = ln.Addr().String()
h.Unlock() h.Unlock()