Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:golangci规范修改 #2984

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bcs-common/common/bcs-health/utils/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
DefaultBcsEndpoints = "bcsdefault"
// EndpointsEventKindLabelKey xxx
// values should be AlarmType's values
EndpointsEventKindLabelKey = "bcs-endpoints-event-kind"
EndpointsEventKindLabelKey = "bcs-endpoints-event-kind" // nolint
// DataIDLabelKey xxx
DataIDLabelKey = "bcs-health-dataid"
)
Expand Down
3 changes: 2 additions & 1 deletion bcs-common/common/tcp/protocol/protocol_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ package protocol
import (
"bytes"
"fmt"
"github.com/Tencent/bk-bcs/bcs-common/common/blog"
"io"

"github.com/Tencent/bk-bcs/bcs-common/common/blog"
)

// protocolBuffer 网络数据解析
Expand Down
3 changes: 2 additions & 1 deletion bcs-common/pkg/bcsapi/storage/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
package storage

import (
mesostype "github.com/Tencent/bk-bcs/bcs-common/common/types"
core "k8s.io/api/core/v1"

mesostype "github.com/Tencent/bk-bcs/bcs-common/common/types"
)

// Pod information from
Expand Down
3 changes: 1 addition & 2 deletions bcs-common/pkg/bcsapiv4/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
"fmt"
"net/http"

"github.com/parnurzeal/gorequest"

restclient "github.com/Tencent/bk-bcs/bcs-common/pkg/esb/client"
"github.com/parnurzeal/gorequest"
)

func configureRequest(r *gorequest.SuperAgent, config *Config) *gorequest.SuperAgent { // nolint
Expand Down
3 changes: 1 addition & 2 deletions bcs-common/pkg/bcsapiv4/mesosdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import (
"fmt"
"net/http"

blog "k8s.io/klog/v2"

"github.com/Tencent/bk-bcs/bcs-common/common/http/httpclient"
commtypes "github.com/Tencent/bk-bcs/bcs-common/common/types"
moduleDiscovery "github.com/Tencent/bk-bcs/bcs-common/pkg/module-discovery"
"github.com/Tencent/bk-bcs/bcs-common/pkg/networkdetection/types"
schedtypes "github.com/Tencent/bk-bcs/bcs-common/pkg/scheduler/types"
blog "k8s.io/klog/v2"
)

// MesosDriver http API SDK definition
Expand Down
6 changes: 3 additions & 3 deletions bcs-common/pkg/bcsapiv4/netservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"strings"
"time"

blog "k8s.io/klog/v2"

"github.com/Tencent/bk-bcs/bcs-common/common/ssl"
bcstypes "github.com/Tencent/bk-bcs/bcs-common/common/types"
"github.com/Tencent/bk-bcs/bcs-common/common/zkclient"
blog "k8s.io/klog/v2"

types "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/netservice"
)

Expand Down Expand Up @@ -222,7 +222,7 @@ func (nc *NetserviceCli) UpdatePool(pool *types.NetPool) error {
blog.Info("udpate pool string:%s", reqDatas)
seq := nc.random.Perm(len(nc.netSvrs))
httpClient, prefix := nc.getHTTPClient(nc.httpClientTimeout)
uri := prefix + nc.netSvrs[seq[0]] + "/v1/pool/" + pool.Cluster + "/" + pool.Net
uri := prefix + nc.netSvrs[seq[0]] + "/v1/pool/" + pool.Cluster + "/" + pool.Net // nolint
request, err := http.NewRequest("PUT", uri, bytes.NewBuffer(reqDatas))
if err != nil {
return fmt.Errorf("update pool create http request failed, %s", err.Error())
Expand Down
8 changes: 4 additions & 4 deletions bcs-common/pkg/bcsapiv4/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"fmt"
"strings"

blog "k8s.io/klog/v2"

"github.com/Tencent/bk-bcs/bcs-common/common/types"
"github.com/Tencent/bk-bcs/bcs-common/common/version"
"github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/storage"
restclient "github.com/Tencent/bk-bcs/bcs-common/pkg/esb/client"
"github.com/Tencent/bk-bcs/bcs-common/pkg/odm/drivers"
registry "github.com/Tencent/bk-bcs/bcs-common/pkg/registryv4"
blog "k8s.io/klog/v2"

"github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/storage"
)

const (
Expand Down Expand Up @@ -119,7 +119,7 @@ type StorageCli struct {

// QueryK8sReplicaSet query k8s replicaset in specified cluster and namespace
func (c *StorageCli) QueryK8sReplicaSet(cluster, namespace, name string) ([]*storage.ReplicaSet, error) {
subPath := "/k8s/dynamic/namespace_resources/clusters/%s/namespaces/" + namespace + "/ReplicaSet?"
subPath := "/k8s/dynamic/namespace_resources/clusters/%s/namespaces/" + namespace + "/ReplicaSet?" // nolint
if name != "" {
subPath += "resourceName=" + name + "&"
}
Expand Down
4 changes: 2 additions & 2 deletions bcs-common/pkg/bcsapiv4/storage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ package storage
import (
"time"

commtypes "github.com/Tencent/bk-bcs/bcs-common/common/types"
schedtype "github.com/Tencent/bk-bcs/bcs-common/pkg/scheduler/types"
appv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"

commtypes "github.com/Tencent/bk-bcs/bcs-common/common/types"
gdv1alpha1 "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/storage/tkex/gamedeployment/v1alpha1"
gsv1alpha1 "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/storage/tkex/gamestatefulset/v1alpha1"
gpav1alpha1 "github.com/Tencent/bk-bcs/bcs-common/pkg/bcsapiv4/storage/tkex/generalpodautoscaler/v1alpha1"
schedtype "github.com/Tencent/bk-bcs/bcs-common/pkg/scheduler/types"
)

// Namespace is k8s namespace
Expand Down
3 changes: 1 addition & 2 deletions bcs-common/pkg/bcsapiv4/storage/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
package storage

import (
core "k8s.io/api/core/v1"

mesostype "github.com/Tencent/bk-bcs/bcs-common/common/types"
core "k8s.io/api/core/v1"
)

// Pod information from
Expand Down
20 changes: 10 additions & 10 deletions bcs-common/pkg/msgqueue/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import (
"time"

"github.com/micro/go-micro/v2/broker"
"github.com/micro/go-plugins/broker/rabbitmq/v2"
"github.com/micro/go-plugins/broker/stan/v2"
rabbitmqv2 "github.com/micro/go-plugins/broker/rabbitmq/v2"
stanv2 "github.com/micro/go-plugins/broker/stan/v2"
"github.com/pkg/errors"
)

// rabbitmqBroker xxx
// rabbitmq broker init: brokerOptions/init/connect
func rabbitmqBroker(q *QueueOptions) (broker.Broker, error) {
var brokerOpts []broker.Option
brokerOpts = append(brokerOpts, broker.Addrs(q.CommonOptions.Address), rabbitmq.ExchangeName(q.Exchange.Name),
rabbitmq.PrefetchCount(q.Exchange.PrefetchCount))
brokerOpts = append(brokerOpts, broker.Addrs(q.CommonOptions.Address), rabbitmqv2.ExchangeName(q.Exchange.Name),
rabbitmqv2.PrefetchCount(q.Exchange.PrefetchCount))
// exchange durable feature
if q.Exchange.Durable {
brokerOpts = append(brokerOpts, rabbitmq.DurableExchange())
brokerOpts = append(brokerOpts, rabbitmqv2.DurableExchange())
}
// prefetchGlobal feature
if q.Exchange.PrefetchGlobal {
brokerOpts = append(brokerOpts, rabbitmq.PrefetchGlobal())
brokerOpts = append(brokerOpts, rabbitmqv2.PrefetchGlobal())
}

brokerRabbit := rabbitmq.NewBroker(brokerOpts...)
brokerRabbit := rabbitmqv2.NewBroker(brokerOpts...)

// init rabbitmq broker
err := brokerRabbit.Init()
Expand All @@ -56,13 +56,13 @@ func rabbitmqBroker(q *QueueOptions) (broker.Broker, error) {
// natstreamingBroker broker init: natsreaming options/init/connect
func natstreamingBroker(q *QueueOptions) (broker.Broker, error) {
var brokerOpts []broker.Option
brokerOpts = append(brokerOpts, stan.ClusterID(q.NatsOptions.ClusterID), broker.Addrs(q.CommonOptions.Address))
brokerOpts = append(brokerOpts, stanv2.ClusterID(q.NatsOptions.ClusterID), broker.Addrs(q.CommonOptions.Address))
// exchange durable feature
if q.NatsOptions.ConnectRetry {
brokerOpts = append(brokerOpts, stan.ConnectTimeout(time.Minute*5), stan.ConnectRetry(true))
brokerOpts = append(brokerOpts, stanv2.ConnectTimeout(time.Minute*5), stanv2.ConnectRetry(true))
}

brokerNatstreaming := stan.NewBroker(brokerOpts...)
brokerNatstreaming := stanv2.NewBroker(brokerOpts...)

// init natstreaming broker
err := brokerNatstreaming.Init()
Expand Down
16 changes: 8 additions & 8 deletions bcs-common/pkg/msgqueue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"fmt"

"github.com/micro/go-micro/v2/broker"
"github.com/micro/go-plugins/broker/rabbitmq/v2"
"github.com/micro/go-plugins/broker/stan/v2"
rabbitmqv2 "github.com/micro/go-plugins/broker/rabbitmq/v2"
stanv2 "github.com/micro/go-plugins/broker/stan/v2"
natstan "github.com/nats-io/stan.go"
"github.com/pkg/errors"

Expand Down Expand Up @@ -99,7 +99,7 @@ func (mq *MsgQueue) Publish(data *broker.Message) error {

switch mq.queueOptions.CommonOptions.QueueKind {
case RABBITMQ:
err = mq.broker.Publish(queueName, data, rabbitmq.DeliveryMode(mq.queueOptions.PublishOptions.DeliveryMode))
err = mq.broker.Publish(queueName, data, rabbitmqv2.DeliveryMode(mq.queueOptions.PublishOptions.DeliveryMode))
case NATSTREAMING:
err = mq.broker.Publish(queueName, data)
default:
Expand Down Expand Up @@ -191,19 +191,19 @@ func (mq *MsgQueue) getSubOptions(queueName string) ([]broker.SubscribeOption, e
subOptions = append(subOptions, broker.DisableAutoAck())
}
if mq.queueOptions.SubscribeOptions.AckOnSuccess {
subOptions = append(subOptions, rabbitmq.AckOnSuccess())
subOptions = append(subOptions, rabbitmqv2.AckOnSuccess())
}

switch mq.queueOptions.CommonOptions.QueueKind {
case RABBITMQ:
if mq.queueOptions.SubscribeOptions.Durable {
subOptions = append(subOptions, rabbitmq.DurableQueue())
subOptions = append(subOptions, rabbitmqv2.DurableQueue())
}
if mq.queueOptions.SubscribeOptions.RequeueOnError {
subOptions = append(subOptions, rabbitmq.RequeueOnError())
subOptions = append(subOptions, rabbitmqv2.RequeueOnError())
}
if len(mq.queueOptions.SubscribeOptions.QueueArguments) > 0 {
subOptions = append(subOptions, rabbitmq.QueueArguments(mq.queueOptions.SubscribeOptions.QueueArguments))
subOptions = append(subOptions, rabbitmqv2.QueueArguments(mq.queueOptions.SubscribeOptions.QueueArguments))
}
case NATSTREAMING:
var natsopts []natstan.SubscriptionOption
Expand All @@ -222,7 +222,7 @@ func (mq *MsgQueue) getSubOptions(queueName string) ([]broker.SubscribeOption, e
if mq.queueOptions.SubscribeOptions.MaxInFlight != 0 {
natsopts = append(natsopts, natstan.MaxInflight(mq.queueOptions.SubscribeOptions.MaxInFlight))
}
subOptions = append(subOptions, stan.SubscribeOption(natsopts...))
subOptions = append(subOptions, stanv2.SubscribeOption(natsopts...))
default:
return nil, errors.New("unsupported queue kind")
}
Expand Down
37 changes: 19 additions & 18 deletions bcs-common/pkg/registryv4/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ import (

// NewEtcdRegistry create etcd registry instance
func NewEtcdRegistry(option *Options) Registry {
//setting default options
// setting default options
if option.TTL == time.Duration(0) {
option.TTL = time.Duration(time.Second * 40)
option.TTL = time.Second * 40
}
if option.Interval == time.Duration(0) {
option.Interval = time.Duration(time.Second * 30)
option.Interval = time.Second * 30
}
//create etcd registry
// create etcd registry
r := etcd.NewRegistry(
registry.Addrs(option.RegistryAddr...),
registry.TLSConfig(option.Config),
)
//creat local service
// creat local service
option.id = uuid.New().String()
if option.Meta == nil {
option.Meta = make(map[string]string)
Expand All @@ -69,15 +69,15 @@ func NewEtcdRegistry(option *Options) Registry {
localCache: make(map[string]*registry.Service),
registered: false,
}
//check event handler
// check event handler
if len(option.Modules) != 0 {
//setting module that watch
// setting module that watch
e.localModules = make(map[string]bool)
for _, name := range option.Modules {
e.localModules[name] = true
_, _ = e.innerGet(name)
}
//start to watch all event
// start to watch all event
go e.innerWatch(e.ctx)
}
return e
Expand Down Expand Up @@ -107,15 +107,15 @@ func (e *etcdRegister) Register() error {
return err
}
e.registered = true
//start background goroutine for interval keep alive
// start background goroutine for interval keep alive
// because we setting ttl for register
go func() {
tick := time.NewTicker(e.option.Interval)
defer tick.Stop()
for {
select {
case <-tick.C:
//ready to keepAlive registered node information
// ready to keepAlive registered node information
if err := e.innerRegister(); err != nil {
blog.Errorf("register %s information %++v failed, %s", e.localService.Name, e.localService, err.Error())
blog.Warnf("try register next tick...")
Expand All @@ -131,13 +131,13 @@ func (e *etcdRegister) Register() error {
func (e *etcdRegister) innerRegister() (err error) {
for i := 0; i < 3; i++ {
if err = e.etcdregistry.Register(e.localService, registry.RegisterTTL(e.option.TTL)); err != nil {
//try again until max failed
// try again until max failed
roption := e.etcdregistry.Options()
blog.Errorf("etcd registry register err, %s, options: %+v\n", err.Error(), roption)
time.Sleep(backoff.Do(i + 1))
continue
}
//register success, clean error
// register success, clean error
err = nil
break
}
Expand All @@ -146,9 +146,9 @@ func (e *etcdRegister) innerRegister() (err error) {

// Deregister clean service information from registry
func (e *etcdRegister) Deregister() error {
//stop background keepalive goroutine
// stop background keepalive goroutine
e.stop()
//clean registered node information
// clean registered node information
if err := e.etcdregistry.Deregister(e.localService); err != nil {
blog.Warnf("Deregister %s information %++v failed, %s", e.localService.Name, e.localService, err.Error())
}
Expand All @@ -171,8 +171,9 @@ func (e *etcdRegister) Get(name string) (*registry.Service, error) {
return svc, nil
}

// nolint
func (e *etcdRegister) innerGet(name string) (*registry.Service, error) {
//first, get details from registry
// first, get details from registry
svcs, err := e.etcdregistry.GetService(name)
if err == registry.ErrNotFound {
blog.Warnf("registry found no module %s under registry, clean local cache.", name)
Expand Down Expand Up @@ -207,7 +208,7 @@ func (e *etcdRegister) innerGet(name string) (*registry.Service, error) {
}

func (e *etcdRegister) innerWatch(ctx context.Context) {
//check if discovery is stopped
// check if discovery is stopped
select {
case <-ctx.Done():
blog.Infof("registry is ready to exit...")
Expand All @@ -219,7 +220,7 @@ func (e *etcdRegister) innerWatch(ctx context.Context) {
watcher, err := e.etcdregistry.Watch(registry.WatchContext(ctx))
if err != nil {
blog.Errorf("registry create watcher for all registry modules failed, %s. retry after a tick", err.Error())
//retry after
// retry after
<-time.After(time.Second * 3)
go e.innerWatch(ctx)
return
Expand Down Expand Up @@ -261,7 +262,7 @@ func (e *etcdRegister) handleEvent(r *registry.Result) {
blog.Errorf("registry get module %s information failed, %s", fullName, err.Error())
return
}
//check event handler
// check event handler
if e.option.EvtHandler != nil {
e.option.EvtHandler(fullName)
}
Expand Down
Loading
Loading