fixup logger usage (#33)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c576749b57
commit
e7d418183b
@ -54,7 +54,9 @@ func (r *Resolver) Domain(req *http.Request) string {
|
||||
// extract the top level domain plus one (e.g. 'myapp.com')
|
||||
domain, err := publicsuffix.EffectiveTLDPlusOne(host)
|
||||
if err != nil {
|
||||
logger.Debugf("Unable to extract domain from %v", host)
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("Unable to extract domain from %v", host)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -324,8 +324,8 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
|
||||
if !mMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api method match %s", req.Method)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api method match %s", req.Method)
|
||||
}
|
||||
|
||||
// 2. try host
|
||||
@ -347,21 +347,21 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
|
||||
if !hMatch {
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api host match %s", req.URL.Host)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api host match %s", req.URL.Host)
|
||||
}
|
||||
|
||||
// 3. try path via google.api path matching
|
||||
for _, pathreg := range cep.pathregs {
|
||||
matches, err := pathreg.Match(path, "")
|
||||
if err != nil {
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api gpath not match %s != %v", path, pathreg)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api gpath not match %s != %v", path, pathreg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api gpath match %s = %v", path, pathreg)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api gpath match %s = %v", path, pathreg)
|
||||
}
|
||||
pMatch = true
|
||||
ctx := req.Context()
|
||||
@ -381,13 +381,13 @@ func (r *registryRouter) Endpoint(req *http.Request) (*api.Service, error) {
|
||||
// 4. try path via pcre path matching
|
||||
for _, pathreg := range cep.pcreregs {
|
||||
if !pathreg.MatchString(req.URL.Path) {
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api pcre path not match %s != %v", path, pathreg)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api pcre path not match %s != %v", path, pathreg)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if logger.V(logger.DebugLevel) {
|
||||
logger.Debugf("api pcre path match %s != %v", path, pathreg)
|
||||
if logger.V(logger.TraceLevel) {
|
||||
logger.Tracef("api pcre path match %s != %v", path, pathreg)
|
||||
}
|
||||
pMatch = true
|
||||
break
|
||||
|
@ -15,6 +15,7 @@ var (
|
||||
|
||||
// Provider is a ACME provider interface
|
||||
type Provider interface {
|
||||
Init(...Option) error
|
||||
// Listen returns a new listener
|
||||
Listen(...string) (net.Listener, error)
|
||||
// TLSConfig returns a tls config
|
||||
|
@ -15,6 +15,10 @@ import (
|
||||
// autoCertACME is the ACME provider from golang.org/x/crypto/acme/autocert
|
||||
type autocertProvider struct{}
|
||||
|
||||
func (a *autocertProvider) Init(opts ...acme.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Listen implements acme.Provider
|
||||
func (a *autocertProvider) Listen(hosts ...string) (net.Listener, error) {
|
||||
return autocert.NewListener(hosts...), nil
|
||||
|
@ -3,13 +3,13 @@ package certmagic
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"github.com/unistack-org/micro/v3/api/server/acme"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
)
|
||||
|
||||
type certmagicProvider struct {
|
||||
@ -48,6 +48,15 @@ func (c *certmagicProvider) TLSConfig(hosts ...string) (*tls.Config, error) {
|
||||
return certmagic.TLS(hosts)
|
||||
}
|
||||
|
||||
func (p *certmagicProvider) Init(opts ...acme.Option) error {
|
||||
if p.opts.Cache != nil {
|
||||
if _, ok := p.opts.Cache.(certmagic.Storage); !ok {
|
||||
return fmt.Errorf("ACME: cache provided doesn't implement certmagic's Storage interface")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewProvider returns a certmagic provider
|
||||
func NewProvider(options ...acme.Option) acme.Provider {
|
||||
opts := acme.DefaultOptions()
|
||||
@ -56,12 +65,6 @@ func NewProvider(options ...acme.Option) acme.Provider {
|
||||
o(&opts)
|
||||
}
|
||||
|
||||
if opts.Cache != nil {
|
||||
if _, ok := opts.Cache.(certmagic.Storage); !ok {
|
||||
logger.Fatal("ACME: cache provided doesn't implement certmagic's Storage interface")
|
||||
}
|
||||
}
|
||||
|
||||
return &certmagicProvider{
|
||||
opts: opts,
|
||||
}
|
||||
|
@ -86,7 +86,10 @@ func (s *httpServer) Start() error {
|
||||
go func() {
|
||||
if err := http.Serve(l, s.mux); err != nil {
|
||||
// temporary fix
|
||||
logger.Error(err)
|
||||
if logger.V(logger.ErrorLevel) {
|
||||
logger.Errorf("serve err: %v", err)
|
||||
}
|
||||
s.Stop()
|
||||
}
|
||||
}()
|
||||
|
||||
|
31
service.go
31
service.go
@ -10,7 +10,6 @@ import (
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
signalutil "github.com/unistack-org/micro/v3/util/signal"
|
||||
)
|
||||
|
||||
@ -62,18 +61,14 @@ func (s *service) Init(opts ...Option) {
|
||||
cmd.Store(&s.opts.Store),
|
||||
cmd.Profile(&s.opts.Profile),
|
||||
); err != nil {
|
||||
logger.Fatal(err)
|
||||
logger.Fatalf("[cmd] init failed: %v", err)
|
||||
}
|
||||
|
||||
// execute the command
|
||||
// TODO: do this in service.Run()
|
||||
if err := s.opts.Cmd.Run(); err != nil {
|
||||
logger.Fatal(err)
|
||||
logger.Fatalf("[cmd] run failed: %v", err)
|
||||
}
|
||||
|
||||
// Explicitly set the table name to the service name
|
||||
name := s.opts.Cmd.App().Name
|
||||
s.opts.Store.Init(store.Table(name))
|
||||
})
|
||||
}
|
||||
|
||||
@ -94,18 +89,19 @@ func (s *service) String() string {
|
||||
}
|
||||
|
||||
func (s *service) Start() error {
|
||||
var err error
|
||||
for _, fn := range s.opts.BeforeStart {
|
||||
if err := fn(); err != nil {
|
||||
if err = fn(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.opts.Server.Start(); err != nil {
|
||||
if err = s.opts.Server.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fn := range s.opts.AfterStart {
|
||||
if err := fn(); err != nil {
|
||||
if err = fn(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -114,25 +110,24 @@ func (s *service) Start() error {
|
||||
}
|
||||
|
||||
func (s *service) Stop() error {
|
||||
var gerr error
|
||||
|
||||
var err error
|
||||
for _, fn := range s.opts.BeforeStop {
|
||||
if err := fn(); err != nil {
|
||||
gerr = err
|
||||
if err = fn(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.opts.Server.Stop(); err != nil {
|
||||
if err = s.opts.Server.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, fn := range s.opts.AfterStop {
|
||||
if err := fn(); err != nil {
|
||||
gerr = err
|
||||
if err = fn(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return gerr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Run() error {
|
||||
|
@ -117,10 +117,14 @@ func (t *tunSubscriber) run() {
|
||||
// receive message
|
||||
m := new(transport.Message)
|
||||
if err := c.Recv(m); err != nil {
|
||||
logger.Error(err)
|
||||
if err = c.Close(); err != nil {
|
||||
if logger.V(logger.ErrorLevel) {
|
||||
logger.Error(err)
|
||||
}
|
||||
if err = c.Close(); err != nil {
|
||||
if logger.V(logger.ErrorLevel) {
|
||||
logger.Error(err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user