Skip to content

Commit

Permalink
fix: fix sql formtat
Browse files Browse the repository at this point in the history
fix: fix cr and add goimports linter
fix: fix cr and add goimports linter
  • Loading branch information
Han-Ya-Jun committed Jul 13, 2023
1 parent c8852dc commit 606c0eb
Show file tree
Hide file tree
Showing 65 changed files with 265 additions and 164 deletions.
51 changes: 51 additions & 0 deletions src/core-api/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
run:
# default concurrency is a available CPU number
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 2m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: false
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

skip-files:
- ".*/mock/.*.go"
- ".*testing.go"

linters:
# enable-all: true
# disable-all: true
disable:
- errcheck
enable:
- nilerr
- nakedret
- lll
- gofmt
- gocritic
- gocyclo
- whitespace
- stylecheck
- misspell
- goimports
# - bodyclose
# - nestif
# - gofumpt
# - godox
# - wsl
# - funlen
# - golint
# - cyclop
fast: false

linters-settings:
stylecheck:
checks: ["-ST1000", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
goimports:
# A comma-separated list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: ""
local-prefixes: "core"
5 changes: 4 additions & 1 deletion src/core-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ init:
go install mvdan.cc/gofumpt@latest
# for golines
go install github.com/segmentio/golines@latest
# for goimports
go install golang.org/x/tools/cmd/goimports@latest

.PHONY: dep
dep:
Expand All @@ -38,7 +40,8 @@ check-license:
.PHONY: fmt
fmt:
golines ./ -m 120 -w --base-formatter gofmt --no-reformat-tags
gofumpt -l -w .
gofumpt -l -w .
goimports -local "core" -l -w .


.PHONY: test
Expand Down
6 changes: 3 additions & 3 deletions src/core-api/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ package cmd
import (
"fmt"

"github.com/getsentry/sentry-go"
"github.com/spf13/viper"

"core/pkg/config"
"core/pkg/database"
"core/pkg/logging"
"core/pkg/metric"
"core/pkg/trace"

"github.com/getsentry/sentry-go"
"github.com/spf13/viper"
)

var globalConfig *config.Config
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"fmt"
"os"

"core/pkg/server"

"github.com/spf13/cobra"
"github.com/spf13/viper"

// Register mysql resource
_ "github.com/go-sql-driver/mysql"

"core/pkg/server"
)

// rootCmd represents the base command when called without any subcommands
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/api/microgateway/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"database/sql"
"errors"

"github.com/gin-gonic/gin"

"core/pkg/service"
"core/pkg/util"

"github.com/gin-gonic/gin"
)

type queryPermissionSerializer struct {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/api/microgateway/public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"database/sql"
"errors"

"github.com/gin-gonic/gin"

"core/pkg/service"
"core/pkg/util"

"github.com/gin-gonic/gin"
)

type queryPublicKeySerializer struct {
Expand Down
6 changes: 3 additions & 3 deletions src/core-api/pkg/api/microgateway/publish_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package microgateway

import (
"core/pkg/service"
"core/pkg/util"

"github.com/gin-gonic/gin"
"github.com/spf13/cast"

"core/pkg/service"
"core/pkg/util"
)

type reportPublishEventSerializer struct {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/app_gateway_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"errors"
"strconv"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
"core/pkg/logging"

"github.com/TencentBlueKing/gopkg/cache"
)

// AppGatewayPermissionKey is the key of app-gateway permission
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/app_gateway_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestAppGatewayPermissionKey_Key(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/app_resource_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"errors"
"strconv"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
"core/pkg/logging"

"github.com/TencentBlueKing/gopkg/cache"
)

// AppResourcePermissionKey is the key of app-resource permission
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/app_resource_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestAppResourcePermissionKey_Key(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"context"
"errors"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// GatewayNameKey is the key of gateway
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestGatewayNameKey_Key(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/jwt_public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"errors"
"strconv"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// JWTPublicKeyCacheKey is the key of jwt public key
Expand Down
7 changes: 4 additions & 3 deletions src/core-api/pkg/cacheimpls/microgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"context"
"errors"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// MicroGatewayKey is the key of micro gateway
Expand Down Expand Up @@ -66,7 +66,8 @@ func GetMicroGateway(ctx context.Context, instanceID string) (microGateway dao.M
// MicroGatewayConfig is the config of micro gateway, it configured on dashboard, saved into db as a json
// the schema is like {secret_key: {jwt_auth: xxxxx}}
// here we use the jwt_auth as the credentials of the micro gateway with the instance id
// Note: The original credentials were a JWT token, and after refactoring we changed to the instance_id + token in the header.
// Note: The original credentials were a JWT token, and after refactoring we changed to the instance_id + token in the
// header.
type MicroGatewayConfig struct {
JwtAuth JwtAuth `json:"jwt_auth"`
}
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/microgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestMicroGatewayKey_Key(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"errors"
"strconv"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// ReleaseKey is the key of release
Expand Down
10 changes: 5 additions & 5 deletions src/core-api/pkg/cacheimpls/release_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"errors"
"strconv"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// ReleaseHistoryCacheKey is the key of jwt public key
Expand All @@ -52,9 +52,9 @@ func retrieveReleaseHistory(ctx context.Context, k cache.Key) (interface{}, erro
}

// GetReleaseHistory will get the jwt public key from cache by ReleaseID
func GetReleaseHistory(ctx context.Context, ReleaseID int64) (releaseHistory dao.ReleaseHistory, err error) {
func GetReleaseHistory(ctx context.Context, releaseID int64) (releaseHistory dao.ReleaseHistory, err error) {
key := ReleaseHistoryCacheKey{
ReleaseID: ReleaseID,
ReleaseID: releaseID,
}
var value interface{}
value, err = cacheGet(ctx, releaseHistoryCache, key)
Expand All @@ -65,7 +65,7 @@ func GetReleaseHistory(ctx context.Context, ReleaseID int64) (releaseHistory dao
var ok bool
releaseHistory, ok = value.(dao.ReleaseHistory)
if !ok {
err = errors.New("not string in cache")
err = errors.New("not ReleaseHistory in cache")
return
}
return
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/release_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestReleaseHistoryCacheKey_Key(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"testing"
"time"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"
"github.com/TencentBlueKing/gopkg/cache/memory"
"github.com/stretchr/testify/assert"

"core/pkg/database/dao"
)

func TestGetMicroGateway_Key(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions src/core-api/pkg/cacheimpls/resource_version_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"errors"
"strconv"

"core/pkg/database/dao"
"core/pkg/logging"

"github.com/TencentBlueKing/gopkg/cache"
jsoniter "github.com/json-iterator/go"

"core/pkg/database/dao"
"core/pkg/logging"
)

// ResourceVersionMappingKey is the key of resource version mapping
Expand Down
4 changes: 2 additions & 2 deletions src/core-api/pkg/cacheimpls/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"errors"
"strconv"

"core/pkg/database/dao"

"github.com/TencentBlueKing/gopkg/cache"

"core/pkg/database/dao"
)

// StageKey is the key of stage
Expand Down
Loading

0 comments on commit 606c0eb

Please sign in to comment.