fixup logger usage (#33)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user