From 3855dc4dda2d5f4ffb2e429cf0ae2941672695f3 Mon Sep 17 00:00:00 2001 From: Youngteac Hong Date: Fri, 3 Nov 2023 15:38:02 +0900 Subject: [PATCH] Bump up golangci-lint and fix lint errors --- .github/workflows/ci.yml | 2 +- Makefile | 2 +- cmd/yorkie/config/config.go | 2 +- pkg/document/crdt/text.go | 8 +-- pkg/llrb/llrb_test.go | 4 +- server/backend/database/memory/database.go | 66 +++++++++++----------- server/backend/database/mongo/client.go | 13 +++-- server/backend/sync/memory/coordinator.go | 2 +- server/backend/sync/memory/locker.go | 6 +- server/rpc/interceptors/admin_auth.go | 5 +- 10 files changed, 53 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d908eefb..8aecd27b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: branches: [ main ] env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' jobs: build: diff --git a/Makefile b/Makefile index adc963f82..f835f821b 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ default: help tools: ## install tools for developing yorkie go install github.com/gogo/protobuf/protoc-gen-gogo@v1.3.2 go install github.com/gogo/protobuf/protoc-gen-gofast@v1.3.2 - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.1 proto: ## generate proto files protoc \ diff --git a/cmd/yorkie/config/config.go b/cmd/yorkie/config/config.go index 21d15aed3..b4a4023b6 100644 --- a/cmd/yorkie/config/config.go +++ b/cmd/yorkie/config/config.go @@ -152,7 +152,7 @@ func Delete() error { } // Preload read configuration file for viper before running command -func Preload(cmd *cobra.Command, args []string) error { +func Preload(_ *cobra.Command, _ []string) error { configPathValue, err := configPath() if err != nil { fmt.Fprintln(os.Stderr, "get config path: %w", err) diff --git a/pkg/document/crdt/text.go b/pkg/document/crdt/text.go index 77f34ce15..a5e81ad1d 100644 --- a/pkg/document/crdt/text.go +++ b/pkg/document/crdt/text.go @@ -135,9 +135,7 @@ func (t *Text) String() string { node := t.rgaTreeSplit.initialHead.next for node != nil { - if node.createdAt().Compare(t.createdAt) == 0 { - // last line - } else if node.removedAt == nil { + if node.createdAt().Compare(t.createdAt) != 0 && node.removedAt == nil { values = append(values, node.String()) } node = node.next @@ -152,9 +150,7 @@ func (t *Text) Marshal() string { node := t.rgaTreeSplit.initialHead.next for node != nil { - if node.createdAt().Compare(t.createdAt) == 0 { - // last line - } else if node.removedAt == nil { + if node.createdAt().Compare(t.createdAt) != 0 && node.removedAt == nil { values = append(values, node.Marshal()) } node = node.next diff --git a/pkg/llrb/llrb_test.go b/pkg/llrb/llrb_test.go index 9003ac1e6..d0ed0d58e 100644 --- a/pkg/llrb/llrb_test.go +++ b/pkg/llrb/llrb_test.go @@ -41,9 +41,9 @@ func (k *intKey) Compare(other llrb.Key) int { return 1 } else if k.key < o.key { return -1 - } else { - return 0 } + + return 0 } type intValue struct { diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index 22b996d89..7a45335cb 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -58,7 +58,7 @@ func (d *DB) Close() error { // FindProjectInfoByPublicKey returns a project by public key. func (d *DB) FindProjectInfoByPublicKey( - ctx context.Context, + _ context.Context, publicKey string, ) (*database.ProjectInfo, error) { txn := d.db.Txn(false) @@ -77,7 +77,7 @@ func (d *DB) FindProjectInfoByPublicKey( // FindProjectInfoByName returns a project by the given name. func (d *DB) FindProjectInfoByName( - ctx context.Context, + _ context.Context, owner types.ID, name string, ) (*database.ProjectInfo, error) { @@ -98,7 +98,7 @@ func (d *DB) FindProjectInfoByName( } // FindProjectInfoByID returns a project by the given id. -func (d *DB) FindProjectInfoByID(ctx context.Context, id types.ID) (*database.ProjectInfo, error) { +func (d *DB) FindProjectInfoByID(_ context.Context, id types.ID) (*database.ProjectInfo, error) { txn := d.db.Txn(false) defer txn.Abort() raw, err := txn.First(tblProjects, "id", id.String()) @@ -134,7 +134,7 @@ func (d *DB) EnsureDefaultUserAndProject( // ensureDefaultUserInfo creates the default user if it does not exist. func (d *DB) ensureDefaultUserInfo( - ctx context.Context, + _ context.Context, username, password string, ) (*database.UserInfo, error) { @@ -167,7 +167,7 @@ func (d *DB) ensureDefaultUserInfo( // ensureDefaultProjectInfo creates the default project if it does not exist. func (d *DB) ensureDefaultProjectInfo( - ctx context.Context, + _ context.Context, defaultUserID types.ID, defaultClientDeactivateThreshold string, ) (*database.ProjectInfo, error) { @@ -196,7 +196,7 @@ func (d *DB) ensureDefaultProjectInfo( // CreateProjectInfo creates a new project. func (d *DB) CreateProjectInfo( - ctx context.Context, + _ context.Context, name string, owner types.ID, clientDeactivateThreshold string, @@ -226,7 +226,7 @@ func (d *DB) CreateProjectInfo( // listProjectInfos returns all project infos rotationally. func (d *DB) listProjectInfos( - ctx context.Context, + _ context.Context, pageSize int, housekeepingLastProjectID types.ID, ) ([]*database.ProjectInfo, error) { @@ -264,7 +264,7 @@ func (d *DB) listProjectInfos( // ListProjectInfos returns all project infos owned by owner. func (d *DB) ListProjectInfos( - ctx context.Context, + _ context.Context, owner types.ID, ) ([]*database.ProjectInfo, error) { txn := d.db.Txn(false) @@ -295,7 +295,7 @@ func (d *DB) ListProjectInfos( // UpdateProjectInfo updates the given project. func (d *DB) UpdateProjectInfo( - ctx context.Context, + _ context.Context, owner types.ID, id types.ID, fields *types.UpdatableProjectFields, @@ -338,7 +338,7 @@ func (d *DB) UpdateProjectInfo( // CreateUserInfo creates a new user. func (d *DB) CreateUserInfo( - ctx context.Context, + _ context.Context, username string, hashedPassword string, ) (*database.UserInfo, error) { @@ -364,7 +364,7 @@ func (d *DB) CreateUserInfo( } // FindUserInfo finds a user by the given username. -func (d *DB) FindUserInfo(ctx context.Context, username string) (*database.UserInfo, error) { +func (d *DB) FindUserInfo(_ context.Context, username string) (*database.UserInfo, error) { txn := d.db.Txn(false) defer txn.Abort() @@ -380,9 +380,7 @@ func (d *DB) FindUserInfo(ctx context.Context, username string) (*database.UserI } // ListUserInfos returns all users. -func (d *DB) ListUserInfos( - ctx context.Context, -) ([]*database.UserInfo, error) { +func (d *DB) ListUserInfos(_ context.Context) ([]*database.UserInfo, error) { txn := d.db.Txn(false) defer txn.Abort() @@ -405,7 +403,7 @@ func (d *DB) ListUserInfos( // ActivateClient activates a client. func (d *DB) ActivateClient( - ctx context.Context, + _ context.Context, projectID types.ID, key string, ) (*database.ClientInfo, error) { @@ -444,7 +442,7 @@ func (d *DB) ActivateClient( } // DeactivateClient deactivates a client. -func (d *DB) DeactivateClient(ctx context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) { +func (d *DB) DeactivateClient(_ context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) { if err := clientID.Validate(); err != nil { return nil, err } @@ -480,7 +478,7 @@ func (d *DB) DeactivateClient(ctx context.Context, projectID, clientID types.ID) } // FindClientInfoByID finds a client by ID. -func (d *DB) FindClientInfoByID(ctx context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) { +func (d *DB) FindClientInfoByID(_ context.Context, projectID, clientID types.ID) (*database.ClientInfo, error) { if err := clientID.Validate(); err != nil { return nil, err } @@ -507,7 +505,7 @@ func (d *DB) FindClientInfoByID(ctx context.Context, projectID, clientID types.I // UpdateClientInfoAfterPushPull updates the client from the given clientInfo // after handling PushPull. func (d *DB) UpdateClientInfoAfterPushPull( - ctx context.Context, + _ context.Context, clientInfo *database.ClientInfo, docInfo *database.DocInfo, ) error { @@ -567,7 +565,7 @@ func (d *DB) UpdateClientInfoAfterPushPull( // findDeactivateCandidatesPerProject finds the clients that need housekeeping per project. func (d *DB) findDeactivateCandidatesPerProject( - ctx context.Context, + _ context.Context, project *database.ProjectInfo, candidatesLimit int, ) ([]*database.ClientInfo, error) { @@ -642,7 +640,7 @@ func (d *DB) FindDeactivateCandidates( // createDocIfNotExist condition is true, create the document if it does not // exist. func (d *DB) FindDocInfoByKeyAndOwner( - ctx context.Context, + _ context.Context, projectID types.ID, clientID types.ID, key key.Key, @@ -703,7 +701,7 @@ func (d *DB) FindDocInfoByKeyAndOwner( // FindDocInfoByKey finds the document of the given key. func (d *DB) FindDocInfoByKey( - ctx context.Context, + _ context.Context, projectID types.ID, key key.Key, ) (*database.DocInfo, error) { @@ -723,7 +721,7 @@ func (d *DB) FindDocInfoByKey( // FindDocInfoByID finds a docInfo of the given ID. func (d *DB) FindDocInfoByID( - ctx context.Context, + _ context.Context, projectID types.ID, id types.ID, ) (*database.DocInfo, error) { @@ -749,7 +747,7 @@ func (d *DB) FindDocInfoByID( // UpdateDocInfoStatusToRemoved updates the status of the document to removed. func (d *DB) UpdateDocInfoStatusToRemoved( - ctx context.Context, + _ context.Context, projectID types.ID, id types.ID, ) error { @@ -787,7 +785,7 @@ func (d *DB) UpdateDocInfoStatusToRemoved( // CreateChangeInfos stores the given changes and doc info. If the // removeDoc condition is true, mark IsRemoved to true in doc info. func (d *DB) CreateChangeInfos( - ctx context.Context, + _ context.Context, projectID types.ID, docInfo *database.DocInfo, initialServerSeq int64, @@ -860,7 +858,7 @@ func (d *DB) CreateChangeInfos( // PurgeStaleChanges delete changes before the smallest in `syncedseqs` to // save storage. func (d *DB) PurgeStaleChanges( - ctx context.Context, + _ context.Context, docID types.ID, ) error { txn := d.db.Txn(true) @@ -931,7 +929,7 @@ func (d *DB) FindChangesBetweenServerSeqs( // FindChangeInfosBetweenServerSeqs returns the changeInfos between two server sequences. func (d *DB) FindChangeInfosBetweenServerSeqs( - ctx context.Context, + _ context.Context, docID types.ID, from int64, to int64, @@ -963,7 +961,7 @@ func (d *DB) FindChangeInfosBetweenServerSeqs( // CreateSnapshotInfo stores the snapshot of the given document. func (d *DB) CreateSnapshotInfo( - ctx context.Context, + _ context.Context, docID types.ID, doc *document.InternalDocument, ) error { @@ -990,7 +988,7 @@ func (d *DB) CreateSnapshotInfo( } // FindSnapshotInfoByID returns the snapshot by the given id. -func (d *DB) FindSnapshotInfoByID(ctx context.Context, id types.ID) (*database.SnapshotInfo, error) { +func (d *DB) FindSnapshotInfoByID(_ context.Context, id types.ID) (*database.SnapshotInfo, error) { txn := d.db.Txn(false) defer txn.Abort() raw, err := txn.First(tblSnapshots, "id", id.String()) @@ -1006,7 +1004,7 @@ func (d *DB) FindSnapshotInfoByID(ctx context.Context, id types.ID) (*database.S // FindClosestSnapshotInfo finds the last snapshot of the given document. func (d *DB) FindClosestSnapshotInfo( - ctx context.Context, + _ context.Context, docID types.ID, serverSeq int64, includeSnapshot bool, @@ -1051,7 +1049,7 @@ func (d *DB) FindClosestSnapshotInfo( // FindMinSyncedSeqInfo finds the minimum synced sequence info. func (d *DB) FindMinSyncedSeqInfo( - ctx context.Context, + _ context.Context, docID types.ID, ) (*database.SyncedSeqInfo, error) { txn := d.db.Txn(false) @@ -1130,7 +1128,7 @@ func (d *DB) UpdateAndFindMinSyncedTicket( // UpdateSyncedSeq updates the syncedSeq of the given client. func (d *DB) UpdateSyncedSeq( - ctx context.Context, + _ context.Context, clientInfo *database.ClientInfo, docID types.ID, serverSeq int64, @@ -1194,7 +1192,7 @@ func (d *DB) UpdateSyncedSeq( // FindDocInfosByPaging returns the documentInfos of the given paging. func (d *DB) FindDocInfosByPaging( - ctx context.Context, + _ context.Context, projectID types.ID, paging types.Paging[types.ID], ) ([]*database.DocInfo, error) { @@ -1244,7 +1242,7 @@ func (d *DB) FindDocInfosByPaging( // FindDocInfosByQuery returns the docInfos which match the given query. func (d *DB) FindDocInfosByQuery( - ctx context.Context, + _ context.Context, projectID types.ID, query string, pageSize int, @@ -1275,7 +1273,7 @@ func (d *DB) FindDocInfosByQuery( // IsDocumentAttached returns whether the document is attached to clients. func (d *DB) IsDocumentAttached( - ctx context.Context, + _ context.Context, projectID types.ID, docID types.ID, excludeClientID types.ID, diff --git a/server/backend/database/mongo/client.go b/server/backend/database/mongo/client.go index 640743e5b..5429f58f7 100644 --- a/server/backend/database/mongo/client.go +++ b/server/backend/database/mongo/client.go @@ -40,6 +40,11 @@ import ( "github.com/yorkie-team/yorkie/server/logging" ) +const ( + // StatusKey is the key of the status field. + StatusKey = "status" +) + // Client is a client that connects to Mongo DB and reads or saves Yorkie data. type Client struct { config *Config @@ -593,8 +598,8 @@ func (c *Client) UpdateClientInfoAfterPushPull( clientDocInfoKey + "client_seq": clientDocInfo.ClientSeq, }, "$set": bson.M{ - clientDocInfoKey + "status": clientDocInfo.Status, - "updated_at": clientInfo.UpdatedAt, + clientDocInfoKey + StatusKey: clientDocInfo.Status, + "updated_at": clientInfo.UpdatedAt, }, } @@ -608,7 +613,7 @@ func (c *Client) UpdateClientInfoAfterPushPull( "$set": bson.M{ clientDocInfoKey + "server_seq": 0, clientDocInfoKey + "client_seq": 0, - clientDocInfoKey + "status": clientDocInfo.Status, + clientDocInfoKey + StatusKey: clientDocInfo.Status, "updated_at": clientInfo.UpdatedAt, }, } @@ -866,7 +871,7 @@ func (c *Client) UpdateDocInfoStatusToRemoved( // CreateChangeInfos stores the given changes and doc info. func (c *Client) CreateChangeInfos( ctx context.Context, - projectID types.ID, + _ types.ID, docInfo *database.DocInfo, initialServerSeq int64, changes []*change.Change, diff --git a/server/backend/sync/memory/coordinator.go b/server/backend/sync/memory/coordinator.go index dfc0e1542..dba6ed0e7 100644 --- a/server/backend/sync/memory/coordinator.go +++ b/server/backend/sync/memory/coordinator.go @@ -45,7 +45,7 @@ func NewCoordinator(serverInfo *sync.ServerInfo) *Coordinator { // NewLocker creates locker of the given key. func (c *Coordinator) NewLocker( - ctx context.Context, + _ context.Context, key sync.Key, ) (sync.Locker, error) { return &internalLocker{ diff --git a/server/backend/sync/memory/locker.go b/server/backend/sync/memory/locker.go index c1e90f5e5..be23937be 100644 --- a/server/backend/sync/memory/locker.go +++ b/server/backend/sync/memory/locker.go @@ -29,14 +29,14 @@ type internalLocker struct { } // Lock locks the mutex. -func (il *internalLocker) Lock(ctx context.Context) error { +func (il *internalLocker) Lock(_ context.Context) error { il.locks.Lock(il.key) return nil } // TryLock locks the mutex if not already locked by another session. -func (il *internalLocker) TryLock(ctx context.Context) error { +func (il *internalLocker) TryLock(_ context.Context) error { if !il.locks.TryLock(il.key) { return sync.ErrAlreadyLocked } @@ -45,7 +45,7 @@ func (il *internalLocker) TryLock(ctx context.Context) error { } // Unlock unlocks the mutex. -func (il *internalLocker) Unlock(ctx context.Context) error { +func (il *internalLocker) Unlock(_ context.Context) error { if err := il.locks.Unlock(il.key); err != nil { return err } diff --git a/server/rpc/interceptors/admin_auth.go b/server/rpc/interceptors/admin_auth.go index 0baff2e0a..10e9993e7 100644 --- a/server/rpc/interceptors/admin_auth.go +++ b/server/rpc/interceptors/admin_auth.go @@ -137,10 +137,7 @@ func isRequiredAuth(method string) bool { } // authenticate does authenticate the request. -func (i *AdminAuthInterceptor) authenticate( - ctx context.Context, - method string, -) (*types.User, error) { +func (i *AdminAuthInterceptor) authenticate(ctx context.Context, _ string) (*types.User, error) { data, ok := grpcmetadata.FromIncomingContext(ctx) if !ok { return nil, grpcstatus.Errorf(codes.Unauthenticated, "metadata is not provided")