fix repocard issues #2
| @@ -8,8 +8,10 @@ import ( | |||||||
| 	"github.com/unistack-org/micro/v3/api/server/acme" | 	"github.com/unistack-org/micro/v3/api/server/acme" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | // Option func | ||||||
| type Option func(o *Options) | type Option func(o *Options) | ||||||
|  |  | ||||||
|  | // Options for api server | ||||||
| type Options struct { | type Options struct { | ||||||
| 	EnableACME   bool | 	EnableACME   bool | ||||||
| 	EnableCORS   bool | 	EnableCORS   bool | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ var ( | |||||||
| 	ErrGatewayTimeout      = &Error{Code: 504} | 	ErrGatewayTimeout      = &Error{Code: 504} | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | // Error tpye | ||||||
| type Error struct { | type Error struct { | ||||||
| 	Id     string | 	Id     string | ||||||
| 	Code   int32 | 	Code   int32 | ||||||
|   | |||||||
| @@ -4,11 +4,13 @@ import "context" | |||||||
|  |  | ||||||
| type loggerKey struct{} | type loggerKey struct{} | ||||||
|  |  | ||||||
|  | // FromContext returns logger from passed context | ||||||
| func FromContext(ctx context.Context) (Logger, bool) { | func FromContext(ctx context.Context) (Logger, bool) { | ||||||
| 	l, ok := ctx.Value(loggerKey{}).(Logger) | 	l, ok := ctx.Value(loggerKey{}).(Logger) | ||||||
| 	return l, ok | 	return l, ok | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // NewContext stores logger into passed context | ||||||
| func NewContext(ctx context.Context, l Logger) context.Context { | func NewContext(ctx context.Context, l Logger) context.Context { | ||||||
| 	return context.WithValue(ctx, loggerKey{}, l) | 	return context.WithValue(ctx, loggerKey{}, l) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,8 +1,8 @@ | |||||||
| // Package log provides a log interface | // Package logger provides a log interface | ||||||
| package logger | package logger | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	// Default logger | 	// DefaultLogger variable | ||||||
| 	DefaultLogger Logger = NewHelper(NewLogger()) | 	DefaultLogger Logger = NewHelper(NewLogger()) | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -24,22 +24,27 @@ type Logger interface { | |||||||
| 	String() string | 	String() string | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Init initialize logger | ||||||
| func Init(opts ...Option) error { | func Init(opts ...Option) error { | ||||||
| 	return DefaultLogger.Init(opts...) | 	return DefaultLogger.Init(opts...) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Fields create logger with specific fields | ||||||
| func Fields(fields map[string]interface{}) Logger { | func Fields(fields map[string]interface{}) Logger { | ||||||
| 	return DefaultLogger.Fields(fields) | 	return DefaultLogger.Fields(fields) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Log writes log with specific level | ||||||
| func Log(level Level, v ...interface{}) { | func Log(level Level, v ...interface{}) { | ||||||
| 	DefaultLogger.Log(level, v...) | 	DefaultLogger.Log(level, v...) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Logf writes formatted log with specific level | ||||||
| func Logf(level Level, format string, v ...interface{}) { | func Logf(level Level, format string, v ...interface{}) { | ||||||
| 	DefaultLogger.Logf(level, format, v...) | 	DefaultLogger.Logf(level, format, v...) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // String return logger name | ||||||
| func String() string { | func String() string { | ||||||
| 	return DefaultLogger.String() | 	return DefaultLogger.String() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ import "time" | |||||||
| type Tags map[string]string | type Tags map[string]string | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	Defaultreporter Reporter | 	DefaultReporter Reporter | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Reporter is an interface for collecting and instrumenting metrics | // Reporter is an interface for collecting and instrumenting metrics | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								micro.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								micro.go
									
									
									
									
									
								
							| @@ -71,10 +71,8 @@ type Event interface { | |||||||
| 	Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error | 	Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error | ||||||
| } | } | ||||||
|  |  | ||||||
| // Type alias to satisfy the deprecation |  | ||||||
| type Publisher = Event |  | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
|  | 	// HeaderPrefix for all headers passed | ||||||
| 	HeaderPrefix = "Micro-" | 	HeaderPrefix = "Micro-" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -104,11 +102,6 @@ func NewEvent(topic string, c client.Client) Event { | |||||||
| 	return &event{c, topic} | 	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 | // RegisterHandler is syntactic sugar for registering a handler | ||||||
| func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error { | func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error { | ||||||
| 	return s.Handle(s.NewHandler(h, opts...)) | 	return s.Handle(s.NewHandler(h, opts...)) | ||||||
|   | |||||||
| @@ -3,9 +3,9 @@ package network | |||||||
| import ( | import ( | ||||||
| 	"github.com/google/uuid" | 	"github.com/google/uuid" | ||||||
| 	"github.com/unistack-org/micro/v3/logger" | 	"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/proxy" | ||||||
| 	"github.com/unistack-org/micro/v3/router" | 	"github.com/unistack-org/micro/v3/router" | ||||||
| 	"github.com/unistack-org/micro/v3/network/tunnel" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type Option func(*Options) | type Option func(*Options) | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ type Resolver interface { | |||||||
| 	Resolve(name string) ([]*Record, error) | 	Resolve(name string) ([]*Record, error) | ||||||
| } | } | ||||||
|  |  | ||||||
| // A resolved record | // Record that resolved | ||||||
| type Record struct { | type Record struct { | ||||||
| 	Address  string `json:"address"` | 	Address  string `json:"address"` | ||||||
| 	Priority int64  `json:"priority"` | 	Priority int64  `json:"priority"` | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ import ( | |||||||
| 	"github.com/unistack-org/micro/v3/tracer" | 	"github.com/unistack-org/micro/v3/tracer" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | // Options server struct | ||||||
| type Options struct { | type Options struct { | ||||||
| 	Codecs       map[string]codec.NewCodec | 	Codecs       map[string]codec.NewCodec | ||||||
| 	Broker       broker.Broker | 	Broker       broker.Broker | ||||||
| @@ -56,6 +57,7 @@ type Options struct { | |||||||
| 	Context context.Context | 	Context context.Context | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // NewOptions returns new options struct with default or passed values | ||||||
| func NewOptions(opts ...Option) Options { | func NewOptions(opts ...Option) Options { | ||||||
| 	options := Options{ | 	options := Options{ | ||||||
| 		Auth:             auth.DefaultAuth, | 		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 { | func Id(id string) Option { | ||||||
| 	return func(o *Options) { | 	return func(o *Options) { | ||||||
| 		o.Id = id | 		o.Id = id | ||||||
|   | |||||||
| @@ -10,12 +10,12 @@ import ( | |||||||
| 	bmemory "github.com/unistack-org/micro/v3/broker/memory" | 	bmemory "github.com/unistack-org/micro/v3/broker/memory" | ||||||
| 	"github.com/unistack-org/micro/v3/client" | 	"github.com/unistack-org/micro/v3/client" | ||||||
| 	"github.com/unistack-org/micro/v3/client/grpc" | 	"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" | 	rmemory "github.com/unistack-org/micro/v3/registry/memory" | ||||||
| 	"github.com/unistack-org/micro/v3/router" | 	"github.com/unistack-org/micro/v3/router" | ||||||
| 	rtreg "github.com/unistack-org/micro/v3/router/registry" | 	rtreg "github.com/unistack-org/micro/v3/router/registry" | ||||||
| 	"github.com/unistack-org/micro/v3/server" | 	"github.com/unistack-org/micro/v3/server" | ||||||
| 	grpcsrv "github.com/unistack-org/micro/v3/server/grpc" | 	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" | 	cw "github.com/unistack-org/micro/v3/util/client" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ func (r *apiRouter) String() string { | |||||||
| 	return "api" | 	return "api" | ||||||
| } | } | ||||||
|  |  | ||||||
| // Router is a hack for API routing | // New router is a hack for API routing | ||||||
| func New(srvs []*registry.Service) router.Router { | func New(srvs []*registry.Service) router.Router { | ||||||
| 	var routes []router.Route | 	var routes []router.Route | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user