fix lint issues (#16)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-13 01:46:16 +03:00 committed by GitHub
parent fd5ed64729
commit abb9937787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 108 additions and 79 deletions

View File

@ -59,22 +59,6 @@ type Service struct {
Services []*register.Service
}
func strip(s string) string {
return strings.TrimSpace(s)
}
func slice(s string) []string {
var sl []string
for _, p := range strings.Split(s, ",") {
if str := strip(p); len(str) > 0 {
sl = append(sl, strip(p))
}
}
return sl
}
// Encode encodes an endpoint to endpoint metadata
func Encode(e *Endpoint) map[string]string {
if e == nil {

View File

@ -36,10 +36,8 @@ func TestRequestToProto(t *testing.T) {
for k, v := range d.Header {
if val, ok := p.Header[k]; !ok {
t.Fatalf("Expected header %s", k)
} else {
if val.Values[0] != v[0] {
t.Fatalf("Expected val %s, got %s", val.Values[0], v[0])
}
} else if val.Values[0] != v[0] {
t.Fatalf("Expected val %s, got %s", val.Values[0], v[0])
}
}
}

View File

@ -129,10 +129,8 @@ func (m *memoryBroker) Publish(ctx context.Context, topic string, msg *Message,
}
if eh != nil {
eh(p)
} else {
if m.opts.Logger.V(logger.ErrorLevel) {
m.opts.Logger.Error(m.opts.Context, err.Error())
}
} else if m.opts.Logger.V(logger.ErrorLevel) {
m.opts.Logger.Error(m.opts.Context, err.Error())
}
continue
}

View File

@ -107,7 +107,7 @@ func (c *defaultConfig) fillValue(ctx context.Context, value reflect.Value, val
if err != nil {
return err
}
value.Set(reflect.ValueOf(float64(v)))
value.Set(reflect.ValueOf(v))
case reflect.Int:
v, err := strconv.ParseInt(val, 10, 0)
if err != nil {
@ -137,7 +137,7 @@ func (c *defaultConfig) fillValue(ctx context.Context, value reflect.Value, val
if err != nil {
return err
}
value.Set(reflect.ValueOf(int64(v)))
value.Set(reflect.ValueOf(v))
case reflect.Uint:
v, err := strconv.ParseUint(val, 10, 0)
if err != nil {
@ -167,7 +167,7 @@ func (c *defaultConfig) fillValue(ctx context.Context, value reflect.Value, val
if err != nil {
return err
}
value.Set(reflect.ValueOf(uint64(v)))
value.Set(reflect.ValueOf(v))
}
return nil
}

View File

@ -7,8 +7,7 @@ import (
// NoopMeter is an noop implementation of Meter
type noopMeter struct {
opts Options
labels Labels
opts Options
}
// NewMeter returns a configured noop reporter:
@ -39,27 +38,47 @@ func (r *noopMeter) Counter(name string, opts ...Option) Counter {
// FloatCounter implements the Meter interface
func (r *noopMeter) FloatCounter(name string, opts ...Option) FloatCounter {
return &noopFloatCounter{}
options := Options{}
for _, o := range opts {
o(&options)
}
return &noopFloatCounter{labels: options.Labels}
}
// Gauge implements the Meter interface
func (r *noopMeter) Gauge(name string, f func() float64, opts ...Option) Gauge {
return &noopGauge{}
options := Options{}
for _, o := range opts {
o(&options)
}
return &noopGauge{labels: options.Labels}
}
// Summary implements the Meter interface
func (r *noopMeter) Summary(name string, opts ...Option) Summary {
return &noopSummary{}
options := Options{}
for _, o := range opts {
o(&options)
}
return &noopSummary{labels: options.Labels}
}
// SummaryExt implements the Meter interface
func (r *noopMeter) SummaryExt(name string, window time.Duration, quantiles []float64, opts ...Option) Summary {
return &noopSummary{}
options := Options{}
for _, o := range opts {
o(&options)
}
return &noopSummary{labels: options.Labels}
}
// Histogram implements the Meter interface
func (r *noopMeter) Histogram(name string, opts ...Option) Histogram {
return &noopHistogram{}
options := Options{}
for _, o := range opts {
o(&options)
}
return &noopHistogram{labels: options.Labels}
}
// Set implements the Meter interface
@ -111,7 +130,9 @@ func (r *noopCounter) Set(uint64) {
}
type noopFloatCounter struct{}
type noopFloatCounter struct {
labels Labels
}
func (r *noopFloatCounter) Add(float64) {
@ -129,13 +150,17 @@ func (r *noopFloatCounter) Sub(float64) {
}
type noopGauge struct{}
type noopGauge struct {
labels Labels
}
func (r *noopGauge) Get() float64 {
return 0
}
type noopSummary struct{}
type noopSummary struct {
labels Labels
}
func (r *noopSummary) Update(float64) {
@ -145,7 +170,9 @@ func (r *noopSummary) UpdateDuration(time.Time) {
}
type noopHistogram struct{}
type noopHistogram struct {
labels Labels
}
func (r *noopHistogram) Reset() {

View File

@ -88,7 +88,7 @@ func NewTransport(opts ...transport.Option) transport.Transport {
}
// initialise
t.Init(opts...)
//t.Init(opts...)
return t
}

View File

@ -72,6 +72,7 @@ func NewOptions(opts ...Option) Options {
}
for _, o := range opts {
//nolint:errcheck
o(&options)
}

View File

@ -57,26 +57,23 @@ func (m *memory) ttlPrune() {
prune := time.NewTicker(ttlPruneTime)
defer prune.Stop()
for {
select {
case <-prune.C:
m.Lock()
for domain, services := range m.records {
for service, versions := range services {
for version, record := range versions {
for id, n := range record.Nodes {
if n.TTL != 0 && time.Since(n.LastSeen) > n.TTL {
if m.opts.Logger.V(logger.DebugLevel) {
m.opts.Logger.Debugf(m.opts.Context, "Register TTL expired for node %s of service %s", n.Id, service)
}
delete(m.records[domain][service][version].Nodes, id)
for range prune.C {
m.Lock()
for domain, services := range m.records {
for service, versions := range services {
for version, record := range versions {
for id, n := range record.Nodes {
if n.TTL != 0 && time.Since(n.LastSeen) > n.TTL {
if m.opts.Logger.V(logger.DebugLevel) {
m.opts.Logger.Debugf(m.opts.Context, "Register TTL expired for node %s of service %s", n.Id, service)
}
delete(m.records[domain][service][version].Nodes, id)
}
}
}
}
m.Unlock()
}
m.Unlock()
}
}

View File

@ -36,7 +36,17 @@ type Route struct {
// Hash returns route hash sum.
func (r *Route) Hash() uint64 {
h := fnv.New64()
h.Reset()
h.Write([]byte(r.Service + r.Address + r.Gateway + r.Network + r.Router + r.Link))
//nolint:errcheck
h.Write([]byte(r.Service))
//nolint:errcheck
h.Write([]byte(r.Address))
//nolint:errcheck
h.Write([]byte(r.Gateway))
//nolint:errcheck
h.Write([]byte(r.Network))
//nolint:errcheck
h.Write([]byte(r.Router))
//nolint:errcheck
h.Write([]byte(r.Link))
return h.Sum64()
}

View File

@ -22,6 +22,7 @@ func (r *random) Select(routes []string, opts ...selector.SelectOption) (selecto
}
// select a random route from the slice
//nolint:gosec
return routes[rand.Intn(len(routes))]
}, nil
}
@ -40,5 +41,5 @@ func (r *random) String() string {
// NewSelector returns a random selector
func NewSelector(opts ...selector.Option) selector.Selector {
return new(random)
return &random{}
}

View File

@ -216,10 +216,13 @@ func (n *noopServer) createSubHandler(sb *subscriber, opts Options) broker.Handl
hdr := make(map[string]string, len(msg.Header))
for k, v := range msg.Header {
if k == "Content-Type" {
continue
}
hdr[k] = v
}
delete(hdr, "Content-Type")
ctx := metadata.NewContext(sb.opts.Context, hdr)
ctx := metadata.NewIncomingContext(sb.opts.Context, hdr)
results := make(chan error, len(sb.handlers))

View File

@ -92,7 +92,9 @@ func (s *service) Init(opts ...Option) error {
var err error
// process options
for _, o := range opts {
o(&s.opts)
if err = o(&s.opts); err != nil {
return err
}
}
for _, cfg := range s.opts.Configs {

View File

@ -11,7 +11,9 @@ import (
func TestMemoryReInit(t *testing.T) {
s := store.NewStore(store.Table("aaa"))
s.Init(store.Table(""))
if err := s.Init(store.Table("")); err != nil {
t.Fatal(err)
}
if len(s.Options().Table) > 0 {
t.Error("Init didn't reinitialise the store")
}
@ -19,25 +21,33 @@ func TestMemoryReInit(t *testing.T) {
func TestMemoryBasic(t *testing.T) {
s := store.NewStore()
s.Init()
if err := s.Init(); err != nil {
t.Fatal(err)
}
basictest(s, t)
}
func TestMemoryPrefix(t *testing.T) {
s := store.NewStore()
s.Init(store.Table("some-prefix"))
if err := s.Init(store.Table("some-prefix")); err != nil {
t.Fatal(err)
}
basictest(s, t)
}
func TestMemoryNamespace(t *testing.T) {
s := store.NewStore()
s.Init(store.Database("some-namespace"))
if err := s.Init(store.Database("some-namespace")); err != nil {
t.Fatal(err)
}
basictest(s, t)
}
func TestMemoryNamespacePrefix(t *testing.T) {
s := store.NewStore()
s.Init(store.Table("some-prefix"), store.Database("some-namespace"))
if err := s.Init(store.Table("some-prefix"), store.Database("some-namespace")); err != nil {
t.Fatal(err)
}
basictest(s, t)
}
@ -53,10 +63,8 @@ func basictest(s store.Store, t *testing.T) {
var val []byte
if err := s.Read(ctx, "Hello", &val); err != nil {
t.Error(err)
} else {
if string(val) != "World" {
t.Errorf("Expected %s, got %s", "World", val)
}
} else if string(val) != "World" {
t.Errorf("Expected %s, got %s", "World", val)
}
time.Sleep(time.Millisecond * 200)
if err := s.Read(ctx, "Hello", &val); err != store.ErrNotFound {

View File

@ -185,6 +185,7 @@ metadata:
{{- end }}
`
//nolint:gosec
var secretTmpl = `
apiVersion: v1
kind: Secret

View File

@ -248,7 +248,8 @@ func (s *Server) handleQuery(query *dns.Msg, from net.Addr) error {
return fmt.Errorf("[ERR] mdns: support for DNS requests with high truncated bit not implemented: %v", *query)
}
var unicastAnswer, multicastAnswer []dns.RR
unicastAnswer := make([]dns.RR, 0, len(query.Question))
multicastAnswer := make([]dns.RR, 0, len(query.Question))
// Handle each question
for _, q := range query.Question {

View File

@ -243,7 +243,7 @@ func MergeMap(a interface{}, b map[string]interface{}) error {
if fva.Elem().Type().Kind() == reflect.Struct {
for i := 0; i < fva.Elem().NumField(); i++ {
field := fva.Elem().Field(i)
if field.Type().Kind() == reflect.Ptr && field.IsNil() && fva.Elem().Type().Field(i).Anonymous == true {
if field.Type().Kind() == reflect.Ptr && field.IsNil() && fva.Elem().Type().Field(i).Anonymous {
field.Set(reflect.New(field.Type().Elem()))
}
}

View File

@ -62,7 +62,7 @@ func (l literal) compile() []op {
}
func (v variable) compile() []op {
var ops []op
ops := make([]op, 0, len(v.segments))
for _, s := range v.segments {
ops = append(ops, s.compile()...)
}
@ -78,11 +78,12 @@ func (v variable) compile() []op {
}
func (t template) Compile() Template {
var rawOps []op
rawOps := make([]op, 0, len(t.segments))
for _, s := range t.segments {
rawOps = append(rawOps, s.compile()...)
}
//ops := make([]int, 0, len(rawOps))
var (
ops []int
pool []string

View File

@ -36,7 +36,7 @@ func (r *request) Codec() codec.Codec {
}
func (r *request) Header() metadata.Metadata {
md, _ := metadata.FromContext(r.context)
md, _ := metadata.FromIncomingContext(r.context)
return md
}

View File

@ -16,12 +16,9 @@ func (c *syncStore) syncManager() {
}
}(i, tickerAggregator, ticker)
}
for {
select {
case i := <-tickerAggregator:
println(i.index, "ticked")
c.processQueue(i.index)
}
for i := range tickerAggregator {
println(i.index, "ticked")
c.processQueue(i.index)
}
}