From a9eff069766fd6ad5acfebae4ff1206bf4d388f6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 2 Nov 2020 13:25:29 +0300 Subject: [PATCH] fix repocard issues (#2) Signed-off-by: Vasiliy Tolstov --- api/server/options.go | 2 ++ errors/errors.go | 1 + logger/context.go | 2 ++ logger/logger.go | 9 +++++++-- metrics/reporter.go | 2 +- micro.go | 9 +-------- network/options.go | 2 +- resolver/resolver.go | 2 +- server/options.go | 4 +++- util/client/client_test.go | 2 +- util/router/router.go | 2 +- 11 files changed, 21 insertions(+), 16 deletions(-) diff --git a/api/server/options.go b/api/server/options.go index 5fbb152b..1f974941 100644 --- a/api/server/options.go +++ b/api/server/options.go @@ -8,8 +8,10 @@ import ( "github.com/unistack-org/micro/v3/api/server/acme" ) +// Option func type Option func(o *Options) +// Options for api server type Options struct { EnableACME bool EnableCORS bool diff --git a/errors/errors.go b/errors/errors.go index a01156cd..971c3f87 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -23,6 +23,7 @@ var ( ErrGatewayTimeout = &Error{Code: 504} ) +// Error tpye type Error struct { Id string Code int32 diff --git a/logger/context.go b/logger/context.go index 6940122d..ebe7f5e1 100644 --- a/logger/context.go +++ b/logger/context.go @@ -4,11 +4,13 @@ import "context" type loggerKey struct{} +// FromContext returns logger from passed context func FromContext(ctx context.Context) (Logger, bool) { l, ok := ctx.Value(loggerKey{}).(Logger) return l, ok } +// NewContext stores logger into passed context func NewContext(ctx context.Context, l Logger) context.Context { return context.WithValue(ctx, loggerKey{}, l) } diff --git a/logger/logger.go b/logger/logger.go index d496e5df..6af487a2 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,8 +1,8 @@ -// Package log provides a log interface +// Package logger provides a log interface package logger var ( - // Default logger + // DefaultLogger variable DefaultLogger Logger = NewHelper(NewLogger()) ) @@ -24,22 +24,27 @@ type Logger interface { String() string } +// Init initialize logger func Init(opts ...Option) error { return DefaultLogger.Init(opts...) } +// Fields create logger with specific fields func Fields(fields map[string]interface{}) Logger { return DefaultLogger.Fields(fields) } +// Log writes log with specific level func Log(level Level, v ...interface{}) { DefaultLogger.Log(level, v...) } +// Logf writes formatted log with specific level func Logf(level Level, format string, v ...interface{}) { DefaultLogger.Logf(level, format, v...) } +// String return logger name func String() string { return DefaultLogger.String() } diff --git a/metrics/reporter.go b/metrics/reporter.go index 90ce104b..0a07ef43 100644 --- a/metrics/reporter.go +++ b/metrics/reporter.go @@ -7,7 +7,7 @@ import "time" type Tags map[string]string var ( - Defaultreporter Reporter + DefaultReporter Reporter ) // Reporter is an interface for collecting and instrumenting metrics diff --git a/micro.go b/micro.go index a1775098..3b26cc52 100644 --- a/micro.go +++ b/micro.go @@ -71,10 +71,8 @@ type Event interface { Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error } -// Type alias to satisfy the deprecation -type Publisher = Event - var ( + // HeaderPrefix for all headers passed HeaderPrefix = "Micro-" ) @@ -104,11 +102,6 @@ func NewEvent(topic string, c client.Client) Event { return &event{c, topic} } -// Deprecated: NewPublisher returns a new Publisher -func NewPublisher(topic string, c client.Client) Event { - return NewEvent(topic, c) -} - // RegisterHandler is syntactic sugar for registering a handler func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error { return s.Handle(s.NewHandler(h, opts...)) diff --git a/network/options.go b/network/options.go index 1dd262e3..90101277 100644 --- a/network/options.go +++ b/network/options.go @@ -3,9 +3,9 @@ package network import ( "github.com/google/uuid" "github.com/unistack-org/micro/v3/logger" + "github.com/unistack-org/micro/v3/network/tunnel" "github.com/unistack-org/micro/v3/proxy" "github.com/unistack-org/micro/v3/router" - "github.com/unistack-org/micro/v3/network/tunnel" ) type Option func(*Options) diff --git a/resolver/resolver.go b/resolver/resolver.go index a6cd6b12..1e3e91e6 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -9,7 +9,7 @@ type Resolver interface { Resolve(name string) ([]*Record, error) } -// A resolved record +// Record that resolved type Record struct { Address string `json:"address"` Priority int64 `json:"priority"` diff --git a/server/options.go b/server/options.go index ef6a0298..f0504df5 100644 --- a/server/options.go +++ b/server/options.go @@ -15,6 +15,7 @@ import ( "github.com/unistack-org/micro/v3/tracer" ) +// Options server struct type Options struct { Codecs map[string]codec.NewCodec Broker broker.Broker @@ -56,6 +57,7 @@ type Options struct { Context context.Context } +// NewOptions returns new options struct with default or passed values func NewOptions(opts ...Option) Options { options := Options{ Auth: auth.DefaultAuth, @@ -104,7 +106,7 @@ func Logger(l logger.Logger) Option { } } -// Unique server id +// Id unique server id func Id(id string) Option { return func(o *Options) { o.Id = id diff --git a/util/client/client_test.go b/util/client/client_test.go index 299147a8..1d8f8447 100644 --- a/util/client/client_test.go +++ b/util/client/client_test.go @@ -10,12 +10,12 @@ import ( bmemory "github.com/unistack-org/micro/v3/broker/memory" "github.com/unistack-org/micro/v3/client" "github.com/unistack-org/micro/v3/client/grpc" + tmemory "github.com/unistack-org/micro/v3/network/transport/memory" rmemory "github.com/unistack-org/micro/v3/registry/memory" "github.com/unistack-org/micro/v3/router" rtreg "github.com/unistack-org/micro/v3/router/registry" "github.com/unistack-org/micro/v3/server" grpcsrv "github.com/unistack-org/micro/v3/server/grpc" - tmemory "github.com/unistack-org/micro/v3/network/transport/memory" cw "github.com/unistack-org/micro/v3/util/client" ) diff --git a/util/router/router.go b/util/router/router.go index 921f7768..151188e8 100644 --- a/util/router/router.go +++ b/util/router/router.go @@ -18,7 +18,7 @@ func (r *apiRouter) String() string { return "api" } -// Router is a hack for API routing +// New router is a hack for API routing func New(srvs []*registry.Service) router.Router { var routes []router.Route