lint fixes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
f182bba6ff
commit
e5bf1448f4
@ -12,7 +12,20 @@ import (
|
|||||||
var (
|
var (
|
||||||
// DefaultClient is the global default client
|
// DefaultClient is the global default client
|
||||||
DefaultClient Client = NewClient()
|
DefaultClient Client = NewClient()
|
||||||
|
// DefaultContentType is the default content-type if not specified
|
||||||
DefaultContentType = "application/json"
|
DefaultContentType = "application/json"
|
||||||
|
// DefaultBackoff is the default backoff function for retries
|
||||||
|
DefaultBackoff = exponentialBackoff
|
||||||
|
// DefaultRetry is the default check-for-retry function for retries
|
||||||
|
DefaultRetry = RetryNever
|
||||||
|
// DefaultRetries is the default number of times a request is tried
|
||||||
|
DefaultRetries = 0
|
||||||
|
// DefaultRequestTimeout is the default request timeout
|
||||||
|
DefaultRequestTimeout = time.Second * 5
|
||||||
|
// DefaultPoolSize sets the connection pool size
|
||||||
|
DefaultPoolSize = 100
|
||||||
|
// DefaultPoolTTL sets the connection pool ttl
|
||||||
|
DefaultPoolTTL = time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is the interface used to make requests to services.
|
// Client is the interface used to make requests to services.
|
||||||
@ -20,10 +33,10 @@ var (
|
|||||||
// It also supports bidirectional streaming of requests.
|
// It also supports bidirectional streaming of requests.
|
||||||
type Client interface {
|
type Client interface {
|
||||||
Name() string
|
Name() string
|
||||||
Init(...Option) error
|
Init(opts ...Option) error
|
||||||
Options() Options
|
Options() Options
|
||||||
NewMessage(topic string, msg interface{}, opts ...MessageOption) Message
|
NewMessage(topic string, msg interface{}, opts ...MessageOption) Message
|
||||||
NewRequest(service, endpoint string, req interface{}, reqOpts ...RequestOption) Request
|
NewRequest(service string, endpoint string, req interface{}, opts ...RequestOption) Request
|
||||||
Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error
|
Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error
|
||||||
Stream(ctx context.Context, req Request, opts ...CallOption) (Stream, error)
|
Stream(ctx context.Context, req Request, opts ...CallOption) (Stream, error)
|
||||||
Publish(ctx context.Context, msg Message, opts ...PublishOption) error
|
Publish(ctx context.Context, msg Message, opts ...PublishOption) error
|
||||||
@ -74,9 +87,9 @@ type Stream interface {
|
|||||||
// The response read
|
// The response read
|
||||||
Response() Response
|
Response() Response
|
||||||
// Send will encode and send a request
|
// Send will encode and send a request
|
||||||
Send(interface{}) error
|
Send(msg interface{}) error
|
||||||
// Recv will decode and read a response
|
// Recv will decode and read a response
|
||||||
Recv(interface{}) error
|
Recv(msg interface{}) error
|
||||||
// Error returns the stream error
|
// Error returns the stream error
|
||||||
Error() error
|
Error() error
|
||||||
// Close closes the stream
|
// Close closes the stream
|
||||||
@ -97,18 +110,3 @@ type MessageOption func(*MessageOptions)
|
|||||||
|
|
||||||
// RequestOption used by NewRequest
|
// RequestOption used by NewRequest
|
||||||
type RequestOption func(*RequestOptions)
|
type RequestOption func(*RequestOptions)
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultBackoff is the default backoff function for retries
|
|
||||||
DefaultBackoff = exponentialBackoff
|
|
||||||
// DefaultRetry is the default check-for-retry function for retries
|
|
||||||
DefaultRetry = RetryNever
|
|
||||||
// DefaultRetries is the default number of times a request is tried
|
|
||||||
DefaultRetries = 0
|
|
||||||
// DefaultRequestTimeout is the default request timeout
|
|
||||||
DefaultRequestTimeout = time.Second * 5
|
|
||||||
// DefaultPoolSize sets the connection pool size
|
|
||||||
DefaultPoolSize = 100
|
|
||||||
// DefaultPoolTTL sets the connection pool ttl
|
|
||||||
DefaultPoolTTL = time.Minute
|
|
||||||
)
|
|
||||||
|
@ -64,13 +64,13 @@ type CallOptions struct {
|
|||||||
Address []string
|
Address []string
|
||||||
// Backoff func
|
// Backoff func
|
||||||
Backoff BackoffFunc
|
Backoff BackoffFunc
|
||||||
// Transport Dial Timeout
|
// DialTimeout is the transport Dial Timeout
|
||||||
DialTimeout time.Duration
|
DialTimeout time.Duration
|
||||||
// Number of Call attempts
|
// Retries is the number of Call attempts
|
||||||
Retries int
|
Retries int
|
||||||
// Check if retriable func
|
// Retry func to be used for retries
|
||||||
Retry RetryFunc
|
Retry RetryFunc
|
||||||
// Request/Response timeout
|
// RequestTimeout specifies request timeout
|
||||||
RequestTimeout time.Duration
|
RequestTimeout time.Duration
|
||||||
// Router to use for this call
|
// Router to use for this call
|
||||||
Router router.Router
|
Router router.Router
|
||||||
@ -78,15 +78,15 @@ type CallOptions struct {
|
|||||||
Selector selector.Selector
|
Selector selector.Selector
|
||||||
// SelectOptions to use when selecting a route
|
// SelectOptions to use when selecting a route
|
||||||
SelectOptions []selector.SelectOption
|
SelectOptions []selector.SelectOption
|
||||||
// Stream timeout for the stream
|
// StreamTimeout timeout for the stream
|
||||||
StreamTimeout time.Duration
|
StreamTimeout time.Duration
|
||||||
// Use the auth token as the authorization header
|
// AuthToken specifies the auth token as the authorization header
|
||||||
AuthToken bool
|
AuthToken bool
|
||||||
// Network to lookup the route within
|
// Network to lookup the route within
|
||||||
Network string
|
Network string
|
||||||
// Middleware for low level call func
|
// CallWrappers is for low level call func
|
||||||
CallWrappers []CallWrapper
|
CallWrappers []CallWrapper
|
||||||
// Context is uded for non default options
|
// Context is used for non default options
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,8 +110,7 @@ func NewPublishOptions(opts ...PublishOption) PublishOptions {
|
|||||||
type PublishOptions struct {
|
type PublishOptions struct {
|
||||||
// Exchange is the routing exchange for the message
|
// Exchange is the routing exchange for the message
|
||||||
Exchange string
|
Exchange string
|
||||||
// Other options for implementations of the interface
|
// Context holds additional options
|
||||||
// can be stored in a context
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,10 +139,11 @@ func NewRequestOptions(opts ...RequestOption) RequestOptions {
|
|||||||
|
|
||||||
// RequestOptions holds client request options
|
// RequestOptions holds client request options
|
||||||
type RequestOptions struct {
|
type RequestOptions struct {
|
||||||
|
// ContentType specify content-type of request
|
||||||
ContentType string
|
ContentType string
|
||||||
|
// Stream says that request is the streaming
|
||||||
Stream bool
|
Stream bool
|
||||||
// Other options for implementations of the interface
|
// Context can hold other options
|
||||||
// can be stored in a context
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ func Codec(contentType string, c codec.Codec) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default content type of the client
|
// ContentType used by default if not specified
|
||||||
func ContentType(ct string) Option {
|
func ContentType(ct string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.ContentType = ct
|
o.ContentType = ct
|
||||||
@ -270,22 +270,21 @@ func Selector(s selector.Selector) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a Wrapper to a list of options passed into the client
|
// Wrap adds a wrapper to the list of options passed into the client
|
||||||
func Wrap(w Wrapper) Option {
|
func Wrap(w Wrapper) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Wrappers = append(o.Wrappers, w)
|
o.Wrappers = append(o.Wrappers, w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a Wrapper to the list of CallFunc wrappers
|
// WrapCall adds a wrapper to the list of CallFunc wrappers
|
||||||
func WrapCall(cw ...CallWrapper) Option {
|
func WrapCall(cw ...CallWrapper) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.CallOptions.CallWrappers = append(o.CallOptions.CallWrappers, cw...)
|
o.CallOptions.CallWrappers = append(o.CallOptions.CallWrappers, cw...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backoff is used to set the backoff function used
|
// Backoff is used to set the backoff function used when retrying Calls
|
||||||
// when retrying Calls
|
|
||||||
func Backoff(fn BackoffFunc) Option {
|
func Backoff(fn BackoffFunc) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.CallOptions.Backoff = fn
|
o.CallOptions.Backoff = fn
|
||||||
@ -307,7 +306,6 @@ func Lookup(l LookupFunc) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retries sets the retry count when making the request.
|
// Retries sets the retry count when making the request.
|
||||||
// Should this be a Call Option?
|
|
||||||
func Retries(i int) Option {
|
func Retries(i int) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.CallOptions.Retries = i
|
o.CallOptions.Retries = i
|
||||||
@ -322,7 +320,6 @@ func Retry(fn RetryFunc) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RequestTimeout is the request timeout.
|
// RequestTimeout is the request timeout.
|
||||||
// Should this be a Call Option?
|
|
||||||
func RequestTimeout(d time.Duration) Option {
|
func RequestTimeout(d time.Duration) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.CallOptions.RequestTimeout = d
|
o.CallOptions.RequestTimeout = d
|
||||||
@ -463,8 +460,6 @@ func WithMessageContentType(ct string) MessageOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request Options
|
|
||||||
|
|
||||||
// WithContentType specifies request content type
|
// WithContentType specifies request content type
|
||||||
func WithContentType(ct string) RequestOption {
|
func WithContentType(ct string) RequestOption {
|
||||||
return func(o *RequestOptions) {
|
return func(o *RequestOptions) {
|
||||||
|
@ -30,7 +30,7 @@ var (
|
|||||||
DefaultCodec Codec = NewCodec()
|
DefaultCodec Codec = NewCodec()
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageType
|
// MessageType specifies message type for codec
|
||||||
type MessageType int
|
type MessageType int
|
||||||
|
|
||||||
// Codec encodes/decodes various types of messages used within micro.
|
// Codec encodes/decodes various types of messages used within micro.
|
||||||
|
@ -255,6 +255,7 @@ func (c *defaultConfig) Name() string {
|
|||||||
return c.opts.Name
|
return c.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewConfig returns new default config source
|
||||||
func NewConfig(opts ...Option) Config {
|
func NewConfig(opts ...Option) Config {
|
||||||
options := NewOptions(opts...)
|
options := NewOptions(opts...)
|
||||||
if len(options.StructTag) == 0 {
|
if len(options.StructTag) == 0 {
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/tracer"
|
"github.com/unistack-org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Options hold the config options
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Name string
|
Name string
|
||||||
AllowFail bool
|
AllowFail bool
|
||||||
@ -32,8 +33,10 @@ type Options struct {
|
|||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Option function signature
|
||||||
type Option func(o *Options)
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// NewOptions new options struct with filed values
|
||||||
func NewOptions(opts ...Option) Options {
|
func NewOptions(opts ...Option) Options {
|
||||||
options := Options{
|
options := Options{
|
||||||
Logger: logger.DefaultLogger,
|
Logger: logger.DefaultLogger,
|
||||||
@ -48,36 +51,42 @@ func NewOptions(opts ...Option) Options {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllowFail allows config source to fail
|
||||||
func AllowFail(b bool) Option {
|
func AllowFail(b bool) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.AllowFail = b
|
o.AllowFail = b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeforeLoad run funcs before config load
|
||||||
func BeforeLoad(fn ...func(context.Context, Config) error) Option {
|
func BeforeLoad(fn ...func(context.Context, Config) error) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.BeforeLoad = fn
|
o.BeforeLoad = fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AfterLoad run funcs after config load
|
||||||
func AfterLoad(fn ...func(context.Context, Config) error) Option {
|
func AfterLoad(fn ...func(context.Context, Config) error) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.AfterLoad = fn
|
o.AfterLoad = fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeforeSave run funcs before save
|
||||||
func BeforeSave(fn ...func(context.Context, Config) error) Option {
|
func BeforeSave(fn ...func(context.Context, Config) error) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.BeforeSave = fn
|
o.BeforeSave = fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AfterSave run fncs after save
|
||||||
func AfterSave(fn ...func(context.Context, Config) error) Option {
|
func AfterSave(fn ...func(context.Context, Config) error) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.AfterSave = fn
|
o.AfterSave = fn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Context pass context
|
||||||
func Context(ctx context.Context) Option {
|
func Context(ctx context.Context) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Context = ctx
|
o.Context = ctx
|
||||||
@ -91,6 +100,7 @@ func Codec(c codec.Codec) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
func Logger(l logger.Logger) Option {
|
func Logger(l logger.Logger) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Logger = l
|
o.Logger = l
|
||||||
|
@ -9,33 +9,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrBadRequest
|
// ErrBadRequest returns then requests contains invalid data
|
||||||
ErrBadRequest = &Error{Code: 400}
|
ErrBadRequest = &Error{Code: 400}
|
||||||
// ErrUnauthorized
|
// ErrUnauthorized returns then user have unauthorized call
|
||||||
ErrUnauthorized = &Error{Code: 401}
|
ErrUnauthorized = &Error{Code: 401}
|
||||||
// ErrForbidden
|
// ErrForbidden returns then user have not access the resource
|
||||||
ErrForbidden = &Error{Code: 403}
|
ErrForbidden = &Error{Code: 403}
|
||||||
// ErrNotFound
|
// ErrNotFound returns then user specify invalid endpoint
|
||||||
ErrNotFound = &Error{Code: 404}
|
ErrNotFound = &Error{Code: 404}
|
||||||
// ErrMethodNotAllowed
|
// ErrMethodNotAllowed returns then user try to get invalid method
|
||||||
ErrMethodNotAllowed = &Error{Code: 405}
|
ErrMethodNotAllowed = &Error{Code: 405}
|
||||||
// ErrTimeout
|
// ErrTimeout returns then timeout exceeded
|
||||||
ErrTimeout = &Error{Code: 408}
|
ErrTimeout = &Error{Code: 408}
|
||||||
// ErrConflict
|
// ErrConflict returns then request create duplicate resource
|
||||||
ErrConflict = &Error{Code: 409}
|
ErrConflict = &Error{Code: 409}
|
||||||
// ErrInternalServerError
|
// ErrInternalServerError returns then server cant process request because of internal error
|
||||||
ErrInternalServerError = &Error{Code: 500}
|
ErrInternalServerError = &Error{Code: 500}
|
||||||
// ErNotImplemented
|
// ErNotImplemented returns then server does not have desired endpoint method
|
||||||
ErNotImplemented = &Error{Code: 501}
|
ErNotImplemented = &Error{Code: 501}
|
||||||
// ErrBadGateway
|
// ErrBadGateway returns then server cant process request
|
||||||
ErrBadGateway = &Error{Code: 502}
|
ErrBadGateway = &Error{Code: 502}
|
||||||
// ErrServiceUnavailable
|
// ErrServiceUnavailable returns then service unavailable
|
||||||
ErrServiceUnavailable = &Error{Code: 503}
|
ErrServiceUnavailable = &Error{Code: 503}
|
||||||
// ErrGatewayTimeout
|
// ErrGatewayTimeout returns then server have long time to process request
|
||||||
ErrGatewayTimeout = &Error{Code: 504}
|
ErrGatewayTimeout = &Error{Code: 504}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error tpye
|
// Error type
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Id string
|
Id string
|
||||||
Code int32
|
Code int32
|
||||||
@ -43,6 +43,7 @@ type Error struct {
|
|||||||
Status string
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error satisfies error interface
|
||||||
func (e *Error) Error() string {
|
func (e *Error) Error() string {
|
||||||
b, _ := json.Marshal(e)
|
b, _ := json.Marshal(e)
|
||||||
return string(b)
|
return string(b)
|
||||||
|
@ -6,7 +6,7 @@ import "context"
|
|||||||
var (
|
var (
|
||||||
// DefaultLogger variable
|
// DefaultLogger variable
|
||||||
DefaultLogger Logger = NewLogger()
|
DefaultLogger Logger = NewLogger()
|
||||||
// DefaultLogger level
|
// DefaultLevel used by logger
|
||||||
DefaultLevel Level = InfoLevel
|
DefaultLevel Level = InfoLevel
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ var (
|
|||||||
defaultMetadataSize = 2
|
defaultMetadataSize = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Iterator used to iterate over metadata with order
|
||||||
type Iterator struct {
|
type Iterator struct {
|
||||||
cur int
|
cur int
|
||||||
cnt int
|
cnt int
|
||||||
@ -32,6 +33,7 @@ type Iterator struct {
|
|||||||
md Metadata
|
md Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next advance iterator to next element
|
||||||
func (iter *Iterator) Next(k, v *string) bool {
|
func (iter *Iterator) Next(k, v *string) bool {
|
||||||
if iter.cur+1 > iter.cnt {
|
if iter.cur+1 > iter.cnt {
|
||||||
return false
|
return false
|
||||||
@ -43,7 +45,7 @@ func (iter *Iterator) Next(k, v *string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate returns run user func with map key, val sorted by key
|
// Iterator returns the itarator for metadata in sorted order
|
||||||
func (md Metadata) Iterator() *Iterator {
|
func (md Metadata) Iterator() *Iterator {
|
||||||
iter := &Iterator{md: md, cnt: len(md)}
|
iter := &Iterator{md: md, cnt: len(md)}
|
||||||
iter.keys = make([]string, 0, iter.cnt)
|
iter.keys = make([]string, 0, iter.cnt)
|
||||||
|
@ -251,6 +251,7 @@ func (m *memoryTransport) Name() string {
|
|||||||
return m.opts.Name
|
return m.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransport returns new memory transport with options
|
||||||
func NewTransport(opts ...Option) Transport {
|
func NewTransport(opts ...Option) Transport {
|
||||||
options := NewOptions(opts...)
|
options := NewOptions(opts...)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/tracer"
|
"github.com/unistack-org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Options holds options for register
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Name string
|
Name string
|
||||||
Addrs []string
|
Addrs []string
|
||||||
|
@ -18,6 +18,7 @@ type Resolver struct {
|
|||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve tries to resolve endpoint address
|
||||||
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
||||||
host, port, err := net.SplitHostPort(name)
|
host, port, err := net.SplitHostPort(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,7 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Resolver is a DNS network resolve
|
// Resolver is a DNS network resolve
|
||||||
type Resolver struct{}
|
type Resolver struct {
|
||||||
|
Address string
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve assumes ID is a domain name e.g micro.mu
|
// Resolve assumes ID is a domain name e.g micro.mu
|
||||||
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
||||||
|
@ -50,13 +50,13 @@ type Server interface {
|
|||||||
// Retrieve the options
|
// Retrieve the options
|
||||||
Options() Options
|
Options() Options
|
||||||
// Register a handler
|
// Register a handler
|
||||||
Handle(Handler) error
|
Handle(h Handler) error
|
||||||
// Create a new handler
|
// Create a new handler
|
||||||
NewHandler(interface{}, ...HandlerOption) Handler
|
NewHandler(h interface{}, opts ...HandlerOption) Handler
|
||||||
// Create a new subscriber
|
// Create a new subscriber
|
||||||
NewSubscriber(string, interface{}, ...SubscriberOption) Subscriber
|
NewSubscriber(topic string, h interface{}, opts ...SubscriberOption) Subscriber
|
||||||
// Register a subscriber
|
// Register a subscriber
|
||||||
Subscribe(Subscriber) error
|
Subscribe(s Subscriber) error
|
||||||
// Start the server
|
// Start the server
|
||||||
Start() error
|
Start() error
|
||||||
// Stop the server
|
// Stop the server
|
||||||
@ -68,9 +68,9 @@ type Server interface {
|
|||||||
// Router handle serving messages
|
// Router handle serving messages
|
||||||
type Router interface {
|
type Router interface {
|
||||||
// ProcessMessage processes a message
|
// ProcessMessage processes a message
|
||||||
ProcessMessage(context.Context, Message) error
|
ProcessMessage(ctx context.Context, msg Message) error
|
||||||
// ServeRequest processes a request to completion
|
// ServeRequest processes a request to completion
|
||||||
ServeRequest(context.Context, Request, Response) error
|
ServeRequest(ctx context.Context, req Request, rsp Response) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message is an async message interface
|
// Message is an async message interface
|
||||||
@ -116,7 +116,7 @@ type Response interface {
|
|||||||
// Encoded writer
|
// Encoded writer
|
||||||
Codec() codec.Codec
|
Codec() codec.Codec
|
||||||
// Write the header
|
// Write the header
|
||||||
WriteHeader(metadata.Metadata)
|
WriteHeader(md metadata.Metadata)
|
||||||
// write a response directly to the client
|
// write a response directly to the client
|
||||||
Write([]byte) error
|
Write([]byte) error
|
||||||
}
|
}
|
||||||
@ -128,8 +128,8 @@ type Response interface {
|
|||||||
type Stream interface {
|
type Stream interface {
|
||||||
Context() context.Context
|
Context() context.Context
|
||||||
Request() Request
|
Request() Request
|
||||||
Send(interface{}) error
|
Send(msg interface{}) error
|
||||||
Recv(interface{}) error
|
Recv(msg interface{}) error
|
||||||
Error() error
|
Error() error
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
// Options contains configuration for the Store
|
// Options contains configuration for the Store
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
// Name specifies store name
|
||||||
Name string
|
Name string
|
||||||
// Nodes contains the addresses or other connection information of the backing storage.
|
// Nodes contains the addresses or other connection information of the backing storage.
|
||||||
// For example, an etcd implementation would contain the nodes of the cluster.
|
// For example, an etcd implementation would contain the nodes of the cluster.
|
||||||
@ -33,8 +34,7 @@ type Options struct {
|
|||||||
Tracer tracer.Tracer
|
Tracer tracer.Tracer
|
||||||
// TLSConfig specifies tls.Config for secure
|
// TLSConfig specifies tls.Config for secure
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
// Context should contain all implementation specific options
|
||||||
// Context should contain all implementation specific options, using context.WithValue.
|
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,13 +292,16 @@ func ListOffset(o uint) ListOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExistsOption specifies Exists call options
|
||||||
type ExistsOption func(*ExistsOptions)
|
type ExistsOption func(*ExistsOptions)
|
||||||
|
|
||||||
|
// ExistsOptions holds options for Exists method
|
||||||
type ExistsOptions struct {
|
type ExistsOptions struct {
|
||||||
Namespace string
|
Namespace string
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewExistsOptions helper for Exists method
|
||||||
func NewExistsOptions(opts ...ExistsOption) ExistsOptions {
|
func NewExistsOptions(opts ...ExistsOption) ExistsOptions {
|
||||||
options := ExistsOptions{
|
options := ExistsOptions{
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
|
@ -186,8 +186,9 @@ func (m *memorySync) String() string {
|
|||||||
return "memory"
|
return "memory"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSync return new memory sync
|
||||||
func NewSync(opts ...Option) Sync {
|
func NewSync(opts ...Option) Sync {
|
||||||
var options Options
|
options := Options{}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ func (t *tracer) Name() string {
|
|||||||
return t.opts.Name
|
return t.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTracer returns new memory tracer
|
||||||
func NewTracer(opts ...Option) Tracer {
|
func NewTracer(opts ...Option) Tracer {
|
||||||
return &tracer{
|
return &tracer{
|
||||||
opts: NewOptions(opts...),
|
opts: NewOptions(opts...),
|
||||||
|
@ -12,11 +12,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bracketSplitter = regexp.MustCompile(`\[|\]`)
|
// ErrInvalidStruct specifies invalid struct error
|
||||||
ErrInvalidStruct = errors.New("invalid struct specified")
|
ErrInvalidStruct = errors.New("invalid struct specified")
|
||||||
|
// ErrInvalidParam specifies invalid url query params
|
||||||
ErrInvalidParam = errors.New("invalid url query param provided")
|
ErrInvalidParam = errors.New("invalid url query param provided")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
bracketSplitter = regexp.MustCompile(`\[|\]`)
|
||||||
|
)
|
||||||
|
|
||||||
func fieldName(name string) string {
|
func fieldName(name string) string {
|
||||||
newstr := make([]rune, 0)
|
newstr := make([]rune, 0)
|
||||||
upper := false
|
upper := false
|
||||||
@ -38,6 +43,7 @@ func fieldName(name string) string {
|
|||||||
return string(newstr)
|
return string(newstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEmpty returns true if value empty
|
||||||
func IsEmpty(v reflect.Value) bool {
|
func IsEmpty(v reflect.Value) bool {
|
||||||
switch getKind(v) {
|
switch getKind(v) {
|
||||||
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
||||||
@ -63,6 +69,7 @@ func IsEmpty(v reflect.Value) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zero creates new zero interface
|
||||||
func Zero(src interface{}) (interface{}, error) {
|
func Zero(src interface{}) (interface{}, error) {
|
||||||
sv := reflect.ValueOf(src)
|
sv := reflect.ValueOf(src)
|
||||||
|
|
||||||
@ -79,6 +86,7 @@ func Zero(src interface{}) (interface{}, error) {
|
|||||||
return dst.Interface(), nil
|
return dst.Interface(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StructFields returns slice of struct fields
|
||||||
func StructFields(src interface{}) ([]reflect.StructField, error) {
|
func StructFields(src interface{}) ([]reflect.StructField, error) {
|
||||||
var fields []reflect.StructField
|
var fields []reflect.StructField
|
||||||
|
|
||||||
@ -149,6 +157,7 @@ func CopyFrom(a, b interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URLMap returns map of url query params
|
||||||
func URLMap(query string) (map[string]interface{}, error) {
|
func URLMap(query string) (map[string]interface{}, error) {
|
||||||
var (
|
var (
|
||||||
mp interface{} = make(map[string]interface{})
|
mp interface{} = make(map[string]interface{})
|
||||||
@ -167,6 +176,7 @@ func URLMap(query string) (map[string]interface{}, error) {
|
|||||||
return mp.(map[string]interface{}), nil
|
return mp.(map[string]interface{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FlattenMap expand key.subkey to nested map
|
||||||
func FlattenMap(a map[string]interface{}) map[string]interface{} {
|
func FlattenMap(a map[string]interface{}) map[string]interface{} {
|
||||||
// preprocess map
|
// preprocess map
|
||||||
nb := make(map[string]interface{}, len(a))
|
nb := make(map[string]interface{}, len(a))
|
||||||
@ -197,6 +207,7 @@ func FlattenMap(a map[string]interface{}) map[string]interface{} {
|
|||||||
return nb
|
return nb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MergeMap merges maps
|
||||||
func MergeMap(a interface{}, b map[string]interface{}) error {
|
func MergeMap(a interface{}, b map[string]interface{}) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -354,11 +365,11 @@ func mergeBool(va, vb reflect.Value) error {
|
|||||||
va.SetBool(true)
|
va.SetBool(true)
|
||||||
}
|
}
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if b, err := strconv.ParseBool(vb.String()); err != nil {
|
b, err := strconv.ParseBool(vb.String())
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
va.SetBool(b)
|
|
||||||
}
|
}
|
||||||
|
va.SetBool(b)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
||||||
}
|
}
|
||||||
@ -390,11 +401,11 @@ func mergeInt(va, vb reflect.Value) error {
|
|||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
va.SetInt(int64(vb.Float()))
|
va.SetInt(int64(vb.Float()))
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if f, err := strconv.ParseInt(vb.String(), 10, va.Type().Bits()); err != nil {
|
f, err := strconv.ParseInt(vb.String(), 10, va.Type().Bits())
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
va.SetInt(f)
|
|
||||||
}
|
}
|
||||||
|
va.SetInt(f)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
||||||
}
|
}
|
||||||
@ -410,11 +421,11 @@ func mergeUint(va, vb reflect.Value) error {
|
|||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
va.SetUint(uint64(vb.Float()))
|
va.SetUint(uint64(vb.Float()))
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if f, err := strconv.ParseUint(vb.String(), 10, va.Type().Bits()); err != nil {
|
f, err := strconv.ParseUint(vb.String(), 10, va.Type().Bits())
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
va.SetUint(f)
|
|
||||||
}
|
}
|
||||||
|
va.SetUint(f)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
||||||
}
|
}
|
||||||
@ -430,11 +441,11 @@ func mergeFloat(va, vb reflect.Value) error {
|
|||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
va.Set(vb)
|
va.Set(vb)
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if f, err := strconv.ParseFloat(vb.String(), va.Type().Bits()); err != nil {
|
f, err := strconv.ParseFloat(vb.String(), va.Type().Bits())
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
va.SetFloat(f)
|
|
||||||
}
|
}
|
||||||
|
va.SetFloat(f)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
return fmt.Errorf("cant merge %v %s with %v %s", va, va.Kind(), vb, vb.Kind())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user