From 8076e410a9ce3a72f3b2bfcb333ac286d6dc2ee2 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 25 Aug 2020 14:33:36 +0300 Subject: [PATCH] fix repocard issues (#20) Signed-off-by: Vasiliy Tolstov --- api/resolver/subdomain/subdomain.go | 2 +- api/server/acme/options.go | 2 +- auth/options.go | 2 +- auth/rules_test.go | 38 ++++++++++++++--------------- broker/broker.go | 1 + client/retry.go | 2 +- config/default_test.go | 2 +- events/options.go | 2 +- proxy/options.go | 2 ++ registry/registry.go | 14 +++++++++-- router/registry/table_test.go | 2 +- router/static/static.go | 2 +- runtime/options.go | 2 +- store/options.go | 4 +-- store/test/store_test.go | 10 ++++---- transport/transport.go | 8 ++++++ util/kubernetes/api/api_test.go | 26 ++++++++++---------- util/mdns/client.go | 2 +- 18 files changed, 72 insertions(+), 51 deletions(-) diff --git a/api/resolver/subdomain/subdomain.go b/api/resolver/subdomain/subdomain.go index 8a2a8c61..d8ece604 100644 --- a/api/resolver/subdomain/subdomain.go +++ b/api/resolver/subdomain/subdomain.go @@ -46,7 +46,7 @@ func (r *Resolver) Domain(req *http.Request) string { return "" } - // check for dev enviroment + // check for dev environment if host == "localhost" || host == "127.0.0.1" { return "" } diff --git a/api/server/acme/options.go b/api/server/acme/options.go index decab3d6..0ebeba40 100644 --- a/api/server/acme/options.go +++ b/api/server/acme/options.go @@ -56,7 +56,7 @@ func OnDemand(b bool) Option { // Cache provides a cache / storage interface to the underlying ACME library // as there is no standard, this needs to be validated by the underlying -// implentation. +// implementation func Cache(c interface{}) Option { return func(o *Options) { o.Cache = c diff --git a/auth/options.go b/auth/options.go index dd50c988..fceede8d 100644 --- a/auth/options.go +++ b/auth/options.go @@ -213,7 +213,7 @@ func NewTokenOptions(opts ...TokenOption) TokenOptions { o(&options) } - // set defualt expiry of token + // set default expiry of token if options.Expiry == 0 { options.Expiry = time.Minute } diff --git a/auth/rules_test.go b/auth/rules_test.go index 12315ed2..c6983b2d 100644 --- a/auth/rules_test.go +++ b/auth/rules_test.go @@ -42,7 +42,7 @@ func TestVerify(t *testing.T) { Account: &Account{}, Resource: srvResource, Rules: []*Rule{ - &Rule{ + { Scope: "", Resource: catchallResource, }, @@ -52,7 +52,7 @@ func TestVerify(t *testing.T) { Name: "CatchallPublicNoAccount", Resource: srvResource, Rules: []*Rule{ - &Rule{ + { Scope: "", Resource: catchallResource, }, @@ -63,7 +63,7 @@ func TestVerify(t *testing.T) { Account: &Account{}, Resource: srvResource, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, }, @@ -73,7 +73,7 @@ func TestVerify(t *testing.T) { Name: "CatchallPrivateNoAccount", Resource: srvResource, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, }, @@ -85,7 +85,7 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: srvResource.Type, @@ -100,7 +100,7 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: srvResource.Type, @@ -118,7 +118,7 @@ func TestVerify(t *testing.T) { Scopes: []string{"neededscope"}, }, Rules: []*Rule{ - &Rule{ + { Scope: "neededscope", Resource: srvResource, }, @@ -131,7 +131,7 @@ func TestVerify(t *testing.T) { Scopes: []string{"neededscope"}, }, Rules: []*Rule{ - &Rule{ + { Scope: "invalidscope", Resource: srvResource, }, @@ -143,7 +143,7 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessDenied, @@ -156,7 +156,7 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessDenied, @@ -169,13 +169,13 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessGranted, Priority: 1, }, - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessDenied, @@ -188,13 +188,13 @@ func TestVerify(t *testing.T) { Resource: srvResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessGranted, Priority: 0, }, - &Rule{ + { Scope: "*", Resource: catchallResource, Access: AccessDenied, @@ -208,7 +208,7 @@ func TestVerify(t *testing.T) { Resource: webResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: webResource, }, @@ -219,7 +219,7 @@ func TestVerify(t *testing.T) { Resource: webResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: webResource.Type, @@ -235,7 +235,7 @@ func TestVerify(t *testing.T) { Resource: webResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: webResource.Type, @@ -250,7 +250,7 @@ func TestVerify(t *testing.T) { Resource: webResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: webResource.Type, @@ -265,7 +265,7 @@ func TestVerify(t *testing.T) { Resource: webResource, Account: &Account{}, Rules: []*Rule{ - &Rule{ + { Scope: "*", Resource: &Resource{ Type: webResource.Type, diff --git a/broker/broker.go b/broker/broker.go index bc5d3165..b9026033 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -16,6 +16,7 @@ type Broker interface { // Handler is used to process messages via a subscription of a topic. type Handler func(*Message) error +// Message is used to transfer data type Message struct { Header map[string]string Body []byte diff --git a/client/retry.go b/client/retry.go index 34632073..95b48297 100644 --- a/client/retry.go +++ b/client/retry.go @@ -6,7 +6,7 @@ import ( "github.com/unistack-org/micro/v3/errors" ) -// note that returning either false or a non-nil error will result in the call not being retried +// RetryFunc that returning either false or a non-nil error will result in the call not being retried type RetryFunc func(ctx context.Context, req Request, retryCount int, err error) (bool, error) // RetryAlways always retry on error diff --git a/config/default_test.go b/config/default_test.go index d19a02e8..0714b367 100644 --- a/config/default_test.go +++ b/config/default_test.go @@ -160,7 +160,7 @@ func TestConfigWatcherDirtyOverrite(t *testing.T) { } runtime.Gosched() - for i, _ := range ss { + for i := range ss { k := fmt.Sprintf("key%d", i) v := fmt.Sprintf("val%d", i) equalS(t, conf.Get(k).String(""), v) diff --git a/events/options.go b/events/options.go index 9c39d91f..f9314528 100644 --- a/events/options.go +++ b/events/options.go @@ -57,7 +57,7 @@ func WithStartAtTime(t time.Time) SubscribeOption { // WriteOptions contains all the options which can be provided when writing an event to a store type WriteOptions struct { // TTL is the duration the event should be recorded for, a zero value TTL indicates the event should - // be stored indefinately + // be stored indefinitely TTL time.Duration } diff --git a/proxy/options.go b/proxy/options.go index 59893902..78ed1b80 100644 --- a/proxy/options.go +++ b/proxy/options.go @@ -6,6 +6,7 @@ import ( "github.com/unistack-org/micro/v3/router" ) +// Options for proxy type Options struct { // Specific endpoint to always call Endpoint string @@ -17,6 +18,7 @@ type Options struct { Links map[string]client.Client } +// Option func signature type Option func(o *Options) // WithEndpoint sets a proxy endpoint diff --git a/registry/registry.go b/registry/registry.go index 0dfc2c61..f74a009c 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -13,9 +13,9 @@ const ( ) var ( - // Not found error when GetService is called + // ErrNotFound returned when GetService is called and no services found ErrNotFound = errors.New("service not found") - // Watcher stopped error when watcher is stopped + // ErrWatcherStopped returned when when watcher is stopped ErrWatcherStopped = errors.New("watcher stopped") ) @@ -33,6 +33,7 @@ type Registry interface { String() string } +// Service holds service registry info type Service struct { Name string `json:"name"` Version string `json:"version"` @@ -41,12 +42,14 @@ type Service struct { Nodes []*Node `json:"nodes"` } +// Node holds node registry info type Node struct { Id string `json:"id"` Address string `json:"address"` Metadata map[string]string `json:"metadata"` } +// Endpoint holds endpoint registry info type Endpoint struct { Name string `json:"name"` Request *Value `json:"request"` @@ -54,20 +57,27 @@ type Endpoint struct { Metadata map[string]string `json:"metadata"` } +// Valud holds additional kv stuff type Value struct { Name string `json:"name"` Type string `json:"type"` Values []*Value `json:"values"` } +// Option func signature type Option func(*Options) +// RegisterOption option is used to register service type RegisterOption func(*RegisterOptions) +// WatchOption option is used to watch service changes type WatchOption func(*WatchOptions) +// DeregisterOption option is used to deregister service type DeregisterOption func(*DeregisterOptions) +// GetOption option is used to get service type GetOption func(*GetOptions) +// ListOption option is used to list services type ListOption func(*ListOptions) diff --git a/router/registry/table_test.go b/router/registry/table_test.go index cdecc27b..db4492fb 100644 --- a/router/registry/table_test.go +++ b/router/registry/table_test.go @@ -58,7 +58,7 @@ func TestDelete(t *testing.T) { t.Fatalf("error adding route: %s", err) } - // should fail to delete non-existant route + // should fail to delete non-existent route prevSvc := route.Service route.Service = "randDest" diff --git a/router/static/static.go b/router/static/static.go index 077eab3e..18f0cfdd 100644 --- a/router/static/static.go +++ b/router/static/static.go @@ -71,7 +71,7 @@ func (t *table) Query(opts ...router.QueryOption) ([]router.Route, error) { options := router.NewQuery(opts...) return []router.Route{ - router.Route{ + { Address: options.Service, Service: options.Address, Gateway: options.Gateway, diff --git a/runtime/options.go b/runtime/options.go index 0f628b6a..a14dfbb9 100644 --- a/runtime/options.go +++ b/runtime/options.go @@ -157,7 +157,7 @@ func WithArgs(args ...string) CreateOption { } } -// WithRetries sets the max retries attemps +// WithRetries sets the max retries attempts func WithRetries(retries int) CreateOption { return func(o *CreateOptions) { o.Retries = retries diff --git a/store/options.go b/store/options.go index 27224731..2107be2f 100644 --- a/store/options.go +++ b/store/options.go @@ -13,7 +13,7 @@ type Options struct { Nodes []string // Database allows multiple isolated stores to be kept in one backend, if supported. Database string - // Table is analagous to a table in database backends or a key prefix in KV backends + // Table is analag for a table in database backends or a key prefix in KV backends Table string // Context should contain all implementation specific options, using context.WithValue. Context context.Context @@ -38,7 +38,7 @@ func Database(db string) Option { } } -// Table is analagous to a table in database backends or a key prefix in KV backends +// Table is analag for a table in database backends or a key prefix in KV backends func Table(t string) Option { return func(o *Options) { o.Table = t diff --git a/store/test/store_test.go b/store/test/store_test.go index fa0ff29b..b5036534 100644 --- a/store/test/store_test.go +++ b/store/test/store_test.go @@ -383,11 +383,11 @@ func expiryTests(s store.Store, t *testing.T) { func suffixPrefixExpiryTests(s store.Store, t *testing.T) { // Write 3 records with various expiry and get with Prefix records := []*store.Record{ - &store.Record{ + { Key: "foo", Value: []byte("foofoo"), }, - &store.Record{ + { Key: "foobar", Value: []byte("foobarfoobar"), Expiry: time.Millisecond * 100, @@ -431,17 +431,17 @@ func suffixPrefixExpiryTests(s store.Store, t *testing.T) { // Write 3 records with various expiry and get with Suffix records = []*store.Record{ - &store.Record{ + { Key: "foo", Value: []byte("foofoo"), }, - &store.Record{ + { Key: "barfoo", Value: []byte("barfoobarfoo"), Expiry: time.Millisecond * 100, }, - &store.Record{ + { Key: "bazbarfoo", Value: []byte("bazbarfoobazbarfoo"), Expiry: 2 * time.Millisecond * 100, diff --git a/transport/transport.go b/transport/transport.go index 312757e0..2ba60f68 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -16,11 +16,13 @@ type Transport interface { String() string } +// Message is used to transfer data type Message struct { Header map[string]string Body []byte } +// Socket bastraction interface type Socket interface { Recv(*Message) error Send(*Message) error @@ -29,22 +31,28 @@ type Socket interface { Remote() string } +// Client is the socket owner type Client interface { Socket } +// Listener is the interface for stream oriented messaging type Listener interface { Addr() string Close() error Accept(func(Socket)) error } +// Option is the option signature type Option func(*Options) +// DialOption is the option signature type DialOption func(*DialOptions) +// ListenOption is the option signature type ListenOption func(*ListenOptions) var ( + // Default dial timeout DefaultDialTimeout = time.Second * 5 ) diff --git a/util/kubernetes/api/api_test.go b/util/kubernetes/api/api_test.go index 46d5f344..26474b17 100644 --- a/util/kubernetes/api/api_test.go +++ b/util/kubernetes/api/api_test.go @@ -19,49 +19,49 @@ type testcase struct { } var tests = []testcase{ - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("service") }, Method: "GET", URI: "/api/v1/namespaces/default/services/", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("service").Name("foo") }, Method: "GET", URI: "/api/v1/namespaces/default/services/foo", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("service").Namespace("test").Name("bar") }, Method: "GET", URI: "/api/v1/namespaces/test/services/bar", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("deployment").Name("foo") }, Method: "GET", URI: "/apis/apps/v1/namespaces/default/deployments/foo", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("deployment").Namespace("test").Name("foo") }, Method: "GET", URI: "/apis/apps/v1/namespaces/test/deployments/foo", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Get().Resource("pod").Params(&Params{LabelSelector: map[string]string{"foo": "bar"}}) }, Method: "GET", URI: "/api/v1/namespaces/default/pods/?labelSelector=foo%3Dbar", }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Post().Resource("service").Name("foo").Body(map[string]string{"foo": "bar"}) }, @@ -69,7 +69,7 @@ var tests = []testcase{ URI: "/api/v1/namespaces/default/services/foo", Body: map[string]string{"foo": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Post().Resource("deployment").Namespace("test").Name("foo").Body(map[string]string{"foo": "bar"}) }, @@ -77,7 +77,7 @@ var tests = []testcase{ URI: "/apis/apps/v1/namespaces/test/deployments/foo", Body: map[string]string{"foo": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Put().Resource("endpoint").Name("baz").Body(map[string]string{"bam": "bar"}) }, @@ -85,7 +85,7 @@ var tests = []testcase{ URI: "/api/v1/namespaces/default/endpoints/baz", Body: map[string]string{"bam": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Patch().Resource("endpoint").Name("baz").Body(map[string]string{"bam": "bar"}) }, @@ -93,7 +93,7 @@ var tests = []testcase{ URI: "/api/v1/namespaces/default/endpoints/baz", Body: map[string]string{"bam": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Patch().Resource("endpoint").Name("baz").SetHeader("foo", "bar") }, @@ -101,7 +101,7 @@ var tests = []testcase{ URI: "/api/v1/namespaces/default/endpoints/baz", Header: map[string]string{"foo": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts).Patch().Resource("deployment").Name("baz").SetHeader("foo", "bar") }, @@ -109,7 +109,7 @@ var tests = []testcase{ URI: "/apis/apps/v1/namespaces/default/deployments/baz", Header: map[string]string{"foo": "bar"}, }, - testcase{ + { ReqFn: func(opts *Options) *Request { return NewRequest(opts). Get(). diff --git a/util/mdns/client.go b/util/mdns/client.go index 3cc30173..08772ef6 100644 --- a/util/mdns/client.go +++ b/util/mdns/client.go @@ -282,7 +282,7 @@ func (c *client) Close() error { return nil } -// setInterface is used to set the query interface, uses sytem +// setInterface is used to set the query interface, uses system // default if not provided func (c *client) setInterface(iface *net.Interface, loopback bool) error { p := ipv4.NewPacketConn(c.ipv4UnicastConn)