From 5e59d599bb6405af3a9ad47a99e8544841e41992 Mon Sep 17 00:00:00 2001 From: Zixuan Liu Date: Fri, 23 Jun 2023 00:04:53 +0800 Subject: [PATCH] chore: format codebase --- Makefile | 10 ++++++++-- client/v2/client.go | 5 +++-- client/v2/middleware.go | 1 + cmd/app/app.go | 15 ++++++++------- cmd/cli/ctx.go | 9 +++++---- cmd/cli/input.go | 3 ++- cmd/cli/main.go | 1 + cmd/cli/rule.go | 3 ++- pkg/adapter/adapter.go | 3 ++- pkg/adapter/adapter_test.go | 7 ++++--- pkg/adapter/badger.go | 3 ++- pkg/adapter/badger_test.go | 5 +++-- pkg/auth/credential_store.go | 3 ++- pkg/cluster/join.go | 3 ++- pkg/cluster/join_test.go | 3 ++- pkg/cluster/listener_test.go | 5 +++-- pkg/core/core.go | 1 + pkg/core/grpc.go | 1 + pkg/core/http.go | 7 ++++--- pkg/handler/grpc/basic_auth.go | 5 +++-- pkg/log/log.go | 1 + pkg/store/adapter.go | 1 + pkg/store/config.go | 3 ++- pkg/store/enforcer.go | 3 ++- pkg/store/fsm.go | 5 +++-- pkg/store/manage.go | 1 + pkg/store/store.go | 5 +++-- 27 files changed, 72 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 47711ea..6bd1853 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ +GOFILES ?= $(shell find . -type f -name '*.go' | grep -v '.pb.go') + .PHONY: license-check license-check: - find . -type f -name '*.go' | grep -v '.pb.go' | xargs go-license --config=.license.yml --verify + go-license --config=.license.yml --verify $(GOFILES) .PHONY: license-format license-format: - find . -type f -name '*.go' | grep -v '.pb.go' | xargs go-license --config=.license.yml + go-license --config=.license.yml $(GOFILES) + +.PHONY: format +format: license-format + goimports -w $(GOFILES) diff --git a/client/v2/client.go b/client/v2/client.go index 92c2f44..2e4128b 100644 --- a/client/v2/client.go +++ b/client/v2/client.go @@ -18,12 +18,13 @@ import ( "context" "encoding/json" "errors" + "log" + "time" + "github.com/casbin/casbin-mesh/proto/command" "github.com/golang/protobuf/proto" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" "google.golang.org/grpc" - "log" - "time" ) type Client struct { diff --git a/client/v2/middleware.go b/client/v2/middleware.go index 66e2c70..54bce44 100644 --- a/client/v2/middleware.go +++ b/client/v2/middleware.go @@ -17,6 +17,7 @@ package client import ( "context" "encoding/base64" + "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) diff --git a/cmd/app/app.go b/cmd/app/app.go index ef46441..d1bef48 100644 --- a/cmd/app/app.go +++ b/cmd/app/app.go @@ -20,13 +20,6 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "github.com/casbin/casbin-mesh/pkg/auth" - "github.com/casbin/casbin-mesh/pkg/cluster" - "github.com/casbin/casbin-mesh/pkg/core" - "github.com/casbin/casbin-mesh/pkg/store" - "github.com/casbin/casbin-mesh/pkg/transport/tcp" - "github.com/rs/cors" - "github.com/soheilhy/cmux" "io" "io/ioutil" "log" @@ -38,6 +31,14 @@ import ( "runtime/pprof" "strings" "time" + + "github.com/casbin/casbin-mesh/pkg/auth" + "github.com/casbin/casbin-mesh/pkg/cluster" + "github.com/casbin/casbin-mesh/pkg/core" + "github.com/casbin/casbin-mesh/pkg/store" + "github.com/casbin/casbin-mesh/pkg/transport/tcp" + "github.com/rs/cors" + "github.com/soheilhy/cmux" ) func New(cfg *Config) (close func() error) { diff --git a/cmd/cli/ctx.go b/cmd/cli/ctx.go index 27108eb..edd4223 100644 --- a/cmd/cli/ctx.go +++ b/cmd/cli/ctx.go @@ -18,15 +18,16 @@ import ( "context" "encoding/json" "fmt" - "github.com/c-bata/go-prompt" - "github.com/casbin/casbin-mesh/client/v2" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/tidwall/pretty" "log" "os" "strconv" "strings" "time" + + "github.com/c-bata/go-prompt" + "github.com/casbin/casbin-mesh/client/v2" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/tidwall/pretty" ) type Context interface { diff --git a/cmd/cli/input.go b/cmd/cli/input.go index 29a4008..9027bfa 100644 --- a/cmd/cli/input.go +++ b/cmd/cli/input.go @@ -16,9 +16,10 @@ package main import ( "fmt" + "os" + "github.com/erikgeiser/promptkit/selection" "github.com/erikgeiser/promptkit/textinput" - "os" ) const customTemplate = ` diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 1695352..1b2f789 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -16,6 +16,7 @@ package main import ( "fmt" + "github.com/c-bata/go-prompt" "github.com/casbin/casbin-mesh/client/v2" ) diff --git a/cmd/cli/rule.go b/cmd/cli/rule.go index 9499491..712f054 100644 --- a/cmd/cli/rule.go +++ b/cmd/cli/rule.go @@ -15,9 +15,10 @@ package main import ( - "github.com/jedib0t/go-pretty/v6/table" "os" "strings" + + "github.com/jedib0t/go-pretty/v6/table" ) // CasbinRule represents a Casbin rule line. diff --git a/pkg/adapter/adapter.go b/pkg/adapter/adapter.go index 9cfabea..0a7b66e 100644 --- a/pkg/adapter/adapter.go +++ b/pkg/adapter/adapter.go @@ -18,10 +18,11 @@ import ( "encoding/csv" "encoding/json" "errors" + "strings" + "github.com/casbin/casbin/v2/model" "github.com/casbin/casbin/v2/persist" "github.com/dgraph-io/badger/v3" - "strings" ) // CasbinRule represents a Casbin rule line. diff --git a/pkg/adapter/adapter_test.go b/pkg/adapter/adapter_test.go index 2ecca7d..7adae47 100644 --- a/pkg/adapter/adapter_test.go +++ b/pkg/adapter/adapter_test.go @@ -15,13 +15,14 @@ package adapter import ( + "io/ioutil" + "os" + "testing" + "github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "io/ioutil" - "os" - "testing" ) const testDB = "test.db" diff --git a/pkg/adapter/badger.go b/pkg/adapter/badger.go index 5d7ba56..30c2fc7 100644 --- a/pkg/adapter/badger.go +++ b/pkg/adapter/badger.go @@ -15,9 +15,10 @@ package adapter import ( - "github.com/dgraph-io/badger/v3" "time" + "github.com/dgraph-io/badger/v3" + "io" "log" "sync" diff --git a/pkg/adapter/badger_test.go b/pkg/adapter/badger_test.go index 2fe7af0..8ff12bb 100644 --- a/pkg/adapter/badger_test.go +++ b/pkg/adapter/badger_test.go @@ -16,11 +16,12 @@ package adapter import ( "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" "os" "strconv" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ) type BadgerTestSuite struct { diff --git a/pkg/auth/credential_store.go b/pkg/auth/credential_store.go index 6037db3..f979fa7 100644 --- a/pkg/auth/credential_store.go +++ b/pkg/auth/credential_store.go @@ -17,8 +17,9 @@ package auth import ( "encoding/json" "errors" - "golang.org/x/crypto/bcrypt" "io" + + "golang.org/x/crypto/bcrypt" ) // BasicAuthProvider is the interface an object must support to return basic auth information. diff --git a/pkg/cluster/join.go b/pkg/cluster/join.go index 13b15d9..e00430c 100644 --- a/pkg/cluster/join.go +++ b/pkg/cluster/join.go @@ -20,7 +20,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/casbin/casbin-mesh/pkg/auth" "io/ioutil" "log" "net" @@ -29,6 +28,8 @@ import ( "strings" "time" + "github.com/casbin/casbin-mesh/pkg/auth" + "github.com/casbin/casbin-mesh/pkg/utils" ) diff --git a/pkg/cluster/join_test.go b/pkg/cluster/join_test.go index 83f9e91..ce64f86 100644 --- a/pkg/cluster/join_test.go +++ b/pkg/cluster/join_test.go @@ -17,12 +17,13 @@ package cluster import ( "encoding/json" "fmt" - "github.com/casbin/casbin-mesh/pkg/auth" "io/ioutil" "net/http" "net/http/httptest" "testing" "time" + + "github.com/casbin/casbin-mesh/pkg/auth" ) const numAttempts int = 3 diff --git a/pkg/cluster/listener_test.go b/pkg/cluster/listener_test.go index acd2e07..7337ea0 100644 --- a/pkg/cluster/listener_test.go +++ b/pkg/cluster/listener_test.go @@ -15,10 +15,11 @@ package cluster import ( - "github.com/stretchr/testify/assert" - "golang.org/x/net/nettest" "net" "testing" + + "github.com/stretchr/testify/assert" + "golang.org/x/net/nettest" ) func TestListener(t *testing.T) { diff --git a/pkg/core/core.go b/pkg/core/core.go index 67f5175..d975f66 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -16,6 +16,7 @@ package core import ( "context" + "github.com/casbin/casbin-mesh/pkg/auth" "github.com/casbin/casbin-mesh/pkg/store" "github.com/casbin/casbin-mesh/proto/command" diff --git a/pkg/core/grpc.go b/pkg/core/grpc.go index 4bca480..da5f13b 100644 --- a/pkg/core/grpc.go +++ b/pkg/core/grpc.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "errors" + "github.com/casbin/casbin-mesh/pkg/auth" grpc2 "github.com/casbin/casbin-mesh/pkg/handler/grpc" "github.com/casbin/casbin-mesh/proto/command" diff --git a/pkg/core/http.go b/pkg/core/http.go index 2bd2f26..5211693 100644 --- a/pkg/core/http.go +++ b/pkg/core/http.go @@ -18,13 +18,14 @@ import ( "bytes" "encoding/json" "fmt" + "io" + "io/ioutil" + http2 "net/http" + "github.com/casbin/casbin-mesh/pkg/auth" "github.com/casbin/casbin-mesh/pkg/handler/http" "github.com/go-playground/validator" "golang.org/x/net/context" - "io" - "io/ioutil" - http2 "net/http" ) type httpService struct { diff --git a/pkg/handler/grpc/basic_auth.go b/pkg/handler/grpc/basic_auth.go index 189bfe6..d53b75d 100644 --- a/pkg/handler/grpc/basic_auth.go +++ b/pkg/handler/grpc/basic_auth.go @@ -19,11 +19,12 @@ import ( "encoding/base64" "errors" "fmt" - "google.golang.org/grpc" - "google.golang.org/grpc/metadata" "log" "net/http" "strings" + + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" ) var ErrUnauthorized = errors.New("unauthorized") diff --git a/pkg/log/log.go b/pkg/log/log.go index d2e33c4..df41a54 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -16,6 +16,7 @@ package log import ( "fmt" + raftbadgerdb "github.com/BBVA/raft-badger" "github.com/hashicorp/raft" ) diff --git a/pkg/store/adapter.go b/pkg/store/adapter.go index 5acdb17..19ac696 100644 --- a/pkg/store/adapter.go +++ b/pkg/store/adapter.go @@ -16,6 +16,7 @@ package store import ( "context" + "github.com/casbin/casbin-mesh/pkg/adapter" "github.com/casbin/casbin-mesh/proto/command" "github.com/golang/protobuf/proto" diff --git a/pkg/store/config.go b/pkg/store/config.go index 9c836b8..38de038 100644 --- a/pkg/store/config.go +++ b/pkg/store/config.go @@ -15,8 +15,9 @@ package store import ( - "github.com/casbin/casbin-mesh/pkg/auth" "log" + + "github.com/casbin/casbin-mesh/pkg/auth" ) // StoreConfig represents the configuration of the underlying Store. diff --git a/pkg/store/enforcer.go b/pkg/store/enforcer.go index 9029c37..3f47a3a 100644 --- a/pkg/store/enforcer.go +++ b/pkg/store/enforcer.go @@ -17,9 +17,10 @@ package store import ( "context" "encoding/json" - _const "github.com/casbin/casbin-mesh/pkg/const" "time" + _const "github.com/casbin/casbin-mesh/pkg/const" + "github.com/casbin/casbin/v2" "github.com/casbin/casbin-mesh/proto/command" diff --git a/pkg/store/fsm.go b/pkg/store/fsm.go index 23873c0..2320ff7 100644 --- a/pkg/store/fsm.go +++ b/pkg/store/fsm.go @@ -20,14 +20,15 @@ import ( "encoding/json" "errors" "fmt" - "github.com/casbin/casbin-mesh/pkg/adapter" - "github.com/casbin/casbin-mesh/pkg/auth" "io" "io/ioutil" "log" "sync" "time" + "github.com/casbin/casbin-mesh/pkg/adapter" + "github.com/casbin/casbin-mesh/pkg/auth" + model2 "github.com/casbin/casbin/v2/model" "github.com/casbin/casbin/v2" diff --git a/pkg/store/manage.go b/pkg/store/manage.go index 5258337..ad00385 100644 --- a/pkg/store/manage.go +++ b/pkg/store/manage.go @@ -16,6 +16,7 @@ package store import ( "context" + "github.com/casbin/casbin-mesh/proto/command" "github.com/golang/protobuf/proto" "github.com/hashicorp/raft" diff --git a/pkg/store/store.go b/pkg/store/store.go index 3eb34b3..152a73e 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -18,8 +18,6 @@ import ( "errors" "expvar" "fmt" - "github.com/casbin/casbin-mesh/pkg/adapter" - "github.com/casbin/casbin-mesh/pkg/auth" "log" "os" "path/filepath" @@ -28,6 +26,9 @@ import ( "sync" "time" + "github.com/casbin/casbin-mesh/pkg/adapter" + "github.com/casbin/casbin-mesh/pkg/auth" + "github.com/golang/protobuf/proto" "github.com/casbin/casbin-mesh/proto/command"