lint: fix all major issues
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -60,6 +60,7 @@ func IsLocal(addr string) bool {
|
||||
}
|
||||
|
||||
// Extract returns a real ip
|
||||
//nolint:gocyclo
|
||||
func Extract(addr string) (string, error) {
|
||||
// if addr specified then its returned
|
||||
if len(addr) > 0 && (addr != "0.0.0.0" && addr != "[::]" && addr != "::") {
|
||||
|
@@ -8,11 +8,13 @@ type buffer struct {
|
||||
*bytes.Buffer
|
||||
}
|
||||
|
||||
// Close reset buffer contents
|
||||
func (b *buffer) Close() error {
|
||||
b.Buffer.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
// New creates new buffer that satisfies Closer interface
|
||||
func New(b *bytes.Buffer) *buffer {
|
||||
if b == nil {
|
||||
b = bytes.NewBuffer(nil)
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// FromRequest creates context with metadata from http.Request
|
||||
func FromRequest(r *http.Request) context.Context {
|
||||
ctx := r.Context()
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
|
@@ -44,6 +44,7 @@ func WriteInternalServerError(w http.ResponseWriter, err error) {
|
||||
Write(w, "application/json", 500, string(rawBody))
|
||||
}
|
||||
|
||||
// NewRoundTripper creates new http RoundTripper
|
||||
func NewRoundTripper(opts ...Option) http.RoundTripper {
|
||||
options := Options{}
|
||||
for _, o := range opts {
|
||||
|
@@ -6,26 +6,31 @@ import (
|
||||
"github.com/unistack-org/micro/v3/network/transport"
|
||||
)
|
||||
|
||||
// Options struct
|
||||
type Options struct {
|
||||
Transport transport.Transport
|
||||
TTL time.Duration
|
||||
Size int
|
||||
}
|
||||
|
||||
// Option func signature
|
||||
type Option func(*Options)
|
||||
|
||||
// Size sets the size
|
||||
func Size(i int) Option {
|
||||
return func(o *Options) {
|
||||
o.Size = i
|
||||
}
|
||||
}
|
||||
|
||||
// Transport sets the transport
|
||||
func Transport(t transport.Transport) Option {
|
||||
return func(o *Options) {
|
||||
o.Transport = t
|
||||
}
|
||||
}
|
||||
|
||||
// TTL specifies ttl
|
||||
func TTL(t time.Duration) Option {
|
||||
return func(o *Options) {
|
||||
o.TTL = t
|
||||
|
@@ -18,6 +18,7 @@ type Pool interface {
|
||||
Release(c Conn, status error) error
|
||||
}
|
||||
|
||||
// Conn conn pool interface
|
||||
type Conn interface {
|
||||
// unique id of connection
|
||||
Id() string
|
||||
@@ -27,8 +28,9 @@ type Conn interface {
|
||||
transport.Client
|
||||
}
|
||||
|
||||
// NewPool creates new connection pool
|
||||
func NewPool(opts ...Option) Pool {
|
||||
var options Options
|
||||
options := Options{}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
@@ -208,6 +208,7 @@ func FlattenMap(a map[string]interface{}) map[string]interface{} {
|
||||
}
|
||||
|
||||
// MergeMap merges maps
|
||||
//nolint:gocyclo
|
||||
func MergeMap(a interface{}, b map[string]interface{}) error {
|
||||
var err error
|
||||
|
||||
@@ -281,6 +282,7 @@ func MergeMap(a interface{}, b map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
func mergeSlice(va, vb reflect.Value) error {
|
||||
switch getKind(vb) {
|
||||
/*
|
||||
|
@@ -78,7 +78,7 @@ func (b *Buffer) Get(n int) []*Entry {
|
||||
return b.vals[delta:]
|
||||
}
|
||||
|
||||
// Return the entries since a specific time
|
||||
// Since returns the entries since a specific time
|
||||
func (b *Buffer) Since(t time.Time) []*Entry {
|
||||
b.RLock()
|
||||
defer b.RUnlock()
|
||||
|
@@ -276,6 +276,7 @@ func (p *parser) accept(term termType) (string, error) {
|
||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
// / "*" / "+" / "," / ";" / "="
|
||||
// pct-encoded = "%" HEXDIG HEXDIG
|
||||
//nolint:gocyclo
|
||||
func expectPChars(t string) error {
|
||||
const (
|
||||
init = iota
|
||||
|
@@ -54,6 +54,7 @@ type PatternOpt func(*patternOptions)
|
||||
// "verb" is the verb part of the pattern. It is empty if the pattern does not have the part.
|
||||
// "version" must be 1 for now.
|
||||
// It returns an error if the given definition is invalid.
|
||||
//nolint:gocyclo
|
||||
func NewPattern(version int, ops []int, pool []string, verb string, opts ...PatternOpt) (Pattern, error) {
|
||||
options := patternOptions{
|
||||
assumeColonVerb: true,
|
||||
@@ -182,6 +183,7 @@ func MustPattern(p Pattern, err error) Pattern {
|
||||
// Match examines components if it matches to the Pattern.
|
||||
// If it matches, the function returns a mapping from field paths to their captured values.
|
||||
// If otherwise, the function returns an error.
|
||||
//nolint:gocyclo
|
||||
func (p Pattern) Match(components []string, verb string) (map[string]string, error) {
|
||||
if p.verb != verb {
|
||||
if p.assumeColonVerb || p.verb != "" {
|
||||
|
@@ -4,11 +4,13 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Pool holds the socket pool
|
||||
type Pool struct {
|
||||
sync.RWMutex
|
||||
pool map[string]*Socket
|
||||
}
|
||||
|
||||
// Get socket from pool
|
||||
func (p *Pool) Get(id string) (*Socket, bool) {
|
||||
// attempt to get existing socket
|
||||
p.RLock()
|
||||
@@ -35,6 +37,7 @@ func (p *Pool) Get(id string) (*Socket, bool) {
|
||||
return socket, false
|
||||
}
|
||||
|
||||
// Release close the socket and delete from pool
|
||||
func (p *Pool) Release(s *Socket) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
@@ -22,10 +22,12 @@ type Socket struct {
|
||||
recv chan *transport.Message
|
||||
}
|
||||
|
||||
// SetLocal sets the local addr
|
||||
func (s *Socket) SetLocal(l string) {
|
||||
s.local = l
|
||||
}
|
||||
|
||||
// SetRemote sets the remote addr
|
||||
func (s *Socket) SetRemote(r string) {
|
||||
s.remote = r
|
||||
}
|
||||
@@ -58,14 +60,17 @@ func (s *Socket) Process(m *transport.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remote returns remote addr
|
||||
func (s *Socket) Remote() string {
|
||||
return s.remote
|
||||
}
|
||||
|
||||
// Local returns local addr
|
||||
func (s *Socket) Local() string {
|
||||
return s.local
|
||||
}
|
||||
|
||||
// Send message by via transport
|
||||
func (s *Socket) Send(m *transport.Message) error {
|
||||
// send a message
|
||||
select {
|
||||
@@ -77,6 +82,7 @@ func (s *Socket) Send(m *transport.Message) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Recv message from transport
|
||||
func (s *Socket) Recv(m *transport.Message) error {
|
||||
// receive a message
|
||||
select {
|
||||
|
@@ -11,10 +11,11 @@ import (
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
)
|
||||
|
||||
// Stream interface
|
||||
type Stream interface {
|
||||
Context() context.Context
|
||||
SendMsg(interface{}) error
|
||||
RecvMsg(interface{}) error
|
||||
SendMsg(msg interface{}) error
|
||||
RecvMsg(msg interface{}) error
|
||||
Close() error
|
||||
}
|
||||
|
||||
@@ -31,23 +32,28 @@ type request struct {
|
||||
context context.Context
|
||||
}
|
||||
|
||||
// Codec returns codec.Codec
|
||||
func (r *request) Codec() codec.Codec {
|
||||
return r.Request.Codec()
|
||||
}
|
||||
|
||||
// Header returns metadata header
|
||||
func (r *request) Header() metadata.Metadata {
|
||||
md, _ := metadata.FromIncomingContext(r.context)
|
||||
return md
|
||||
}
|
||||
|
||||
// Read returns stream data
|
||||
func (r *request) Read() ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Request returns server.Request
|
||||
func (s *stream) Request() server.Request {
|
||||
return s.request
|
||||
}
|
||||
|
||||
// Send sends message
|
||||
func (s *stream) Send(v interface{}) error {
|
||||
err := s.Stream.SendMsg(v)
|
||||
if err != nil {
|
||||
@@ -58,6 +64,7 @@ func (s *stream) Send(v interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Recv receives data
|
||||
func (s *stream) Recv(v interface{}) error {
|
||||
err := s.Stream.RecvMsg(v)
|
||||
if err != nil {
|
||||
@@ -68,6 +75,7 @@ func (s *stream) Recv(v interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Error returns error that stream holds
|
||||
func (s *stream) Error() error {
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Package syncs will sync multiple stores
|
||||
// Package sync will sync multiple stores
|
||||
package sync
|
||||
|
||||
import (
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
)
|
||||
|
||||
// Options holds the options for token
|
||||
type Options struct {
|
||||
// Store to persist the tokens
|
||||
Store store.Store
|
||||
@@ -15,6 +16,7 @@ type Options struct {
|
||||
PrivateKey string
|
||||
}
|
||||
|
||||
// Option func signature
|
||||
type Option func(o *Options)
|
||||
|
||||
// WithStore sets the token providers store
|
||||
@@ -38,8 +40,9 @@ func WithPrivateKey(key string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// NewOptions returns options struct filled by opts
|
||||
func NewOptions(opts ...Option) Options {
|
||||
var options Options
|
||||
options := Options{}
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
@@ -50,11 +53,13 @@ func NewOptions(opts ...Option) Options {
|
||||
return options
|
||||
}
|
||||
|
||||
// GenerateOptions holds the generate options
|
||||
type GenerateOptions struct {
|
||||
// Expiry for the token
|
||||
Expiry time.Duration
|
||||
}
|
||||
|
||||
// GenerateOption func signature
|
||||
type GenerateOption func(o *GenerateOptions)
|
||||
|
||||
// WithExpiry for the generated account's token expires
|
||||
|
@@ -23,6 +23,7 @@ type Provider interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// Token holds the auth token
|
||||
type Token struct {
|
||||
// The actual token
|
||||
Token string `json:"token"`
|
||||
|
Reference in New Issue
Block a user