Skip to content

Commit

Permalink
fix golangci-lint problems (#2428)
Browse files Browse the repository at this point in the history
* golangci-lint

* golangci-lint
  • Loading branch information
AlkaidChan authored Aug 21, 2023
1 parent 3decb85 commit 2a8c12a
Show file tree
Hide file tree
Showing 51 changed files with 121 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,4 @@ func (p *proxy) initBizsOfTmplSpaces() {
bizsOfTS.Bizs[bizID] = struct{}{}
}
logs.Infof("init bizs of template spaces success, len(biz):%d", len(resp.BizIds))

return
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// AdaptAuthOptions convert bscp auth resource to iam action id and resources
func AdaptAuthOptions(a *meta.ResourceAttribute) (client.ActionID, []client.Resource, error) {
if a == nil {
return "", nil, errf.New(errf.InvalidParameter, fmt.Sprintf("resource attribute is not set"))
return "", nil, errf.New(errf.InvalidParameter, "resource attribute is not set")
}

// skip actions do not need to relate to resources
Expand Down
8 changes: 4 additions & 4 deletions bcs-services/bcs-bscp/cmd/auth-server/service/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ func (g *gateway) setFilter(next http.Handler) http.Handler {
module = paths[4]
} else {
logs.Errorf("received url path length not conform to the regulations, path: %s", r.URL.Path)
fmt.Fprintf(w, errf.New(http.StatusNotFound, "Not Found").Error())
fmt.Fprint(w, errf.New(http.StatusNotFound, "Not Found").Error())
return
}

switch moduleType(module) {
case iamModule:
if err := iamRequestFilter(g.iamSys, w, r); err != nil {
fmt.Fprintf(w, errf.Error(err).Error())
fmt.Fprint(w, errf.Error(err).Error())
return
}

case authModule:
if err := authRequestFilter(w, r); err != nil {
fmt.Fprintf(w, errf.Error(err).Error())
fmt.Fprint(w, errf.Error(err).Error())
return
}

case initialModule, userModule, spaceModule:

default:
logs.Errorf("received unknown module's request req: %v", r)
fmt.Fprintf(w, errf.New(http.StatusNotFound, "Not Found").Error())
fmt.Fprint(w, errf.New(http.StatusNotFound, "Not Found").Error())
return
}

Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-bscp/cmd/auth-server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

Expand Down Expand Up @@ -129,7 +130,7 @@ func newClientSet(sd serviced.Discover, tls cc.TLSConfig, iamSettings cc.IAM, di

if !tls.Enable() {
// dial without ssl
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
// dial with ssl.
tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile,
Expand Down
28 changes: 14 additions & 14 deletions bcs-services/bcs-bscp/cmd/cache-service/service/cache/keys/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (k keyGenerator) ReleasedGroup(bizID uint32, appID uint32) string {
func (k keyGenerator) ReleasedGroupTtlSec(withRange bool) int {

if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.releasedGroupTTLRange[1]-k.releasedGroupTTLRange[0]) + k.releasedGroupTTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.releasedGroupTTLRange[1]-k.releasedGroupTTLRange[0]) + k.releasedGroupTTLRange[0]
return seconds
}

Expand All @@ -93,8 +93,8 @@ func (k keyGenerator) CredentialMatchedCI(bizID uint32, credential string) strin
func (k keyGenerator) CredentialMatchedCITtlSec(withRange bool) int {

if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.credentialMatchedCITTLRange[1]-
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.credentialMatchedCITTLRange[1]-
k.credentialMatchedCITTLRange[0]) + k.credentialMatchedCITTLRange[0]
return seconds
}
Expand All @@ -114,8 +114,8 @@ func (k keyGenerator) Credential(bizID uint32, str string) string {
// CredentialTtlSec generate the credential's TTL seconds
func (k keyGenerator) CredentialTtlSec(withRange bool) int {
if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.credentialTTLRange[1]-k.credentialTTLRange[0]) + k.credentialTTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.credentialTTLRange[1]-k.credentialTTLRange[0]) + k.credentialTTLRange[0]
return seconds
}
return k.credentialTTLRange[0]
Expand All @@ -135,8 +135,8 @@ func (k keyGenerator) ReleasedCI(bizID uint32, releaseID uint32) string {
func (k keyGenerator) ReleasedCITtlSec(withRange bool) int {

if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.releasedCITTLRange[1]-k.releasedCITTLRange[0]) + k.releasedCITTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.releasedCITTLRange[1]-k.releasedCITTLRange[0]) + k.releasedCITTLRange[0]
return seconds
}

Expand All @@ -156,8 +156,8 @@ func (k keyGenerator) ReleasedHook(bizID uint32, releaseID uint32) string {
func (k keyGenerator) ReleasedHookTtlSec(withRange bool) int {

if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.releasedHookTTLRange[1]-k.releasedHookTTLRange[0]) + k.releasedHookTTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.releasedHookTTLRange[1]-k.releasedHookTTLRange[0]) + k.releasedHookTTLRange[0]
return seconds
}

Expand Down Expand Up @@ -186,8 +186,8 @@ func (k keyGenerator) AppMeta(bizID uint32, appID uint32) string {
func (k keyGenerator) AppMetaTtlSec(withRange bool) int {

if withRange {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.appMetaTTLRange[1]-k.appMetaTTLRange[0]) + k.appMetaTTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.appMetaTTLRange[1]-k.appMetaTTLRange[0]) + k.appMetaTTLRange[0]
return seconds
}

Expand All @@ -201,8 +201,8 @@ func (k keyGenerator) NullValue() string {

// NullKeyTtlSec return the null key's ttl seconds
func (k keyGenerator) NullKeyTtlSec() int {
rand.Seed(time.Now().UnixNano())
seconds := rand.Intn(k.nullKeyTTLRange[1]-k.nullKeyTTLRange[0]) + k.nullKeyTTLRange[0]
r := rand.New(rand.NewSource(time.Now().UnixNano()))
seconds := r.Intn(k.nullKeyTTLRange[1]-k.nullKeyTTLRange[0]) + k.nullKeyTTLRange[0]
return seconds
}

Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-bscp/cmd/cache-service/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"bscp.io/pkg/cc"
"bscp.io/pkg/dal/bedis"
Expand Down Expand Up @@ -85,7 +86,7 @@ func newCacheServiceMux() (*runtime.ServeMux, error) {
tls := network.TLS
if !tls.Enable() {
// dial without ssl
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
// dial with ssl.
tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ func (s *Service) UpdateCredentialScope(ctx context.Context, req *pbcs.UpdateCre
CredentialId: req.CredentialId,
}

for _, add := range req.AddScope {
r.Created = append(r.Created, add)
}

for _, updated := range req.AlterScope {
r.Updated = append(r.Updated, updated)
}

for _, del := range req.DelId {
r.Deleted = append(r.Deleted, del)
}
r.Created = append(r.Created, req.AddScope...)
r.Updated = append(r.Updated, req.AlterScope...)
r.Deleted = append(r.Deleted, req.DelId...)

_, err = s.client.DS.UpdateCredentialScopes(grpcKit.RpcCtx(), r)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-bscp/cmd/config-server/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"bscp.io/pkg/cc"
"bscp.io/pkg/logs"
Expand Down Expand Up @@ -79,7 +80,7 @@ func newConfigServerMux() (*runtime.ServeMux, error) {
tls := network.TLS
if !tls.Enable() {
// dial without ssl
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
// dial with ssl.
tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile,
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-bscp/cmd/config-server/service/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (s *Service) ListHooks(ctx context.Context, req *pbcs.ListHooksReq) (*pbcs.
}

if !req.All {
if req.Start < 0 {
if req.Start == 0 {
return nil, errors.New("start has to be greater than 0")
}

if req.Limit < 0 {
if req.Limit == 0 {
return nil, errors.New("limit has to be greater than 0")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func (s *Service) ListHookRevisions(ctx context.Context, req *pbcs.ListHookRevis
}

if !req.All {
if req.Start < 0 {
if req.Start == 0 {
return nil, errors.New("start has to be greater than 0")
}

if req.Limit < 0 {
if req.Limit == 0 {
return nil, errors.New("limit has to be greater than 0")
}

Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-bscp/cmd/config-server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

// Service do all the data service's work
Expand Down Expand Up @@ -89,7 +90,7 @@ func newClientSet(sd serviced.Discover, tls cc.TLSConfig) (*ClientSet, error) {

if !tls.Enable() {
// dial without ssl
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
// dial with ssl.
tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,64 +120,6 @@ func mig20230526152150GormUp(tx *gorm.DB) error {
// mig20230526152150GormDown for down migration
func mig20230526152150GormDown(tx *gorm.DB) error {

// Hook 脚本
type Hook struct {
ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"`

// Spec is specifics of the resource defined with user
Name string `gorm:"type:varchar(64) not null;uniqueIndex:idx_bizID_name,priority:2"`
Meme string `gorm:"type:varchar(64) not null"`
Type string `gorm:"type:varchar(64) not null"`
Tag string `gorm:"type:varchar(64) not null"`

// Attachment is attachment info of the resource
BizID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_bizID_name,priority:1"`

// Revision is revision info of the resource
Creator string `gorm:"type:varchar(64) not null"`
Reviser string `gorm:"type:varchar(64) not null"`
CreatedAt time.Time `gorm:"type:datetime(6) not null"`
UpdatedAt time.Time `gorm:"type:datetime(6) not null"`
}

// HookRevision 脚本版本
type HookRevision struct {
ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"`

// Spec is specifics of the resource defined with user
Name string `gorm:"type:varchar(64) not null;uniqueIndex:idx_bizID_revisionName,priority:2"`
Meme string `gorm:"type:varchar(64) not null"`
State string `gorm:"type:varchar(64) not null"`
Content string `gorm:"type:longtext"`

// Attachment is attachment info of the resource
BizID uint `gorm:"type:bigint(1) unsigned not null"`
HookID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_bizID_revisionName,priority:1"`

// Revision is revision info of the resource
Creator string `gorm:"type:varchar(64) not null"`
Reviser string `gorm:"type:varchar(64) not null"`
CreatedAt time.Time `gorm:"type:datetime(6) not null"`
UpdatedAt time.Time `gorm:"type:datetime(6) not null"`
}

// ReleasedHook : 已随配置项版本发布的配置脚本
type ReleasedHook struct {
ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey;autoIncrement:false"`
APPID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_appID_releaseID_hookType,priority:1"`
ReleaseID uint `gorm:"type:bigint(1) unsigned not null;uniqueIndex:idx_appID_releaseID_hookType,priority:2"`
HookID uint `gorm:"type:bigint(1) unsigned not null"`
HookRevisionID uint `gorm:"type:bigint(1) unsigned not null"`
HookName string `gorm:"type:varchar(64) not null"`
HookRevisionName string `gorm:"type:varchar(64) not null"`
Content string `gorm:"type:longtext"`
ScriptType string `gorm:"type:varchar(64) not null"`
HookType string `gorm:"type:varchar(64) not null;uniqueIndex:idx_appID_releaseID_hookType,priority:3"`
BizID uint `gorm:"type:bigint(1) unsigned not null"`
Reviser string `gorm:"type:varchar(64) not null"`
UpdatedAt time.Time `gorm:"type:datetime(6) not null"`
}

// IDGenerators : ID生成器
type IDGenerators struct {
ID uint `gorm:"type:bigint(1) unsigned not null;primaryKey"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ func (m *Migrator) MigrationStatus() error {
mg := m.Migrations[v]

if mg.done {
fmt.Println(fmt.Sprintf("Migration %s completed", mg.Name))
fmt.Printf("Migration %s completed\n", mg.Name)
} else {
fmt.Println(fmt.Sprintf("Migration %s pending", mg.Name))
fmt.Printf("Migration %s pending\n", mg.Name)
}
}

Expand Down
3 changes: 2 additions & 1 deletion bcs-services/bcs-bscp/cmd/data-service/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"bscp.io/pkg/cc"
"bscp.io/pkg/dal/dao"
Expand Down Expand Up @@ -82,7 +83,7 @@ func newDataServiceMux() (*runtime.ServeMux, error) {
tls := network.TLS
if !tls.Enable() {
// dial without ssl
opts = append(opts, grpc.WithInsecure())
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
// dial with ssl.
tlsC, err := tools.ClientTLSConfVerify(tls.InsecureSkipVerify, tls.CAFile, tls.CertFile, tls.KeyFile,
Expand Down
4 changes: 1 addition & 3 deletions bcs-services/bcs-bscp/cmd/feed-server/bll/eventc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ func (eq *eventQueue) popAll() []*types.EventMeta {
defer eq.lock.Unlock()

copied := make([]*types.EventMeta, len(eq.queue))
for idx := range eq.queue {
copied[idx] = eq.queue[idx]
}
copy(copied, eq.queue)

// reset the queue.
eq.queue = make([]*types.EventMeta, 0)
Expand Down
3 changes: 3 additions & 0 deletions bcs-services/bcs-bscp/cmd/feed-server/bll/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (rs *ReleasedService) ListAppLatestReleaseMeta(kt *kit.Kit, opts *types.App
}

pre, post, err := rs.cache.ReleasedHook.Get(kt, opts.BizID, releaseID)
if err != nil {
return nil, err
}

uriDec := rs.provider.URIDecorator(opts.BizID)
meta := &types.AppLatestReleaseMeta{
Expand Down
4 changes: 2 additions & 2 deletions bcs-services/bcs-bscp/pkg/cc/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package cc
import (
"errors"
"fmt"
"io/ioutil"
"os"

"bscp.io/pkg/config"
"github.com/spf13/viper"
Expand Down Expand Up @@ -67,7 +67,7 @@ func mergeConfigFile(filenames []string) ([]byte, error) {
masterConf := map[string]interface{}{}

for _, filename := range filenames {
file, err := ioutil.ReadFile(filename)
file, err := os.ReadFile(filename)
if err != nil {
return nil, fmt.Errorf("load Setting from file: %s failed, err: %v", filename, err)
}
Expand Down
3 changes: 0 additions & 3 deletions bcs-services/bcs-bscp/pkg/criteria/errf/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ const (
UnHealth int32 = 4000009
// ErrGroupAlreadyPublished means the group has already been published in specified app.
ErrGroupAlreadyPublished int32 = 4000010

// endOfThisScope is a flag to show this scope's error code's end.
endOfThisScope int32 = 4089999
)

// Note: Sidecar related error code scope, ranges at [4090000, 409999]
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/pkg/criteria/errf/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func New(code int32, message string) error {

// Newf create an error with error code and formatted message.
func Newf(code int32, format string, args ...interface{}) error {
return &ErrorF{Code: code, Message: fmt.Sprintf(format, args)}
return &ErrorF{Code: code, Message: fmt.Sprintf(format, args...)}
}

const grpcErrPrefix = "rpc error: code = Unknown desc = "
Expand Down
Loading

0 comments on commit 2a8c12a

Please sign in to comment.