From ff8851fd9f7a0d21c8c463fb5f2b23fc6f101085 Mon Sep 17 00:00:00 2001 From: boojack Date: Sat, 18 Mar 2023 22:34:22 +0800 Subject: [PATCH] fix: golangci-lint version (#1381) * chore: update interface declare * chore: update args * chore: update * chore: update --- .github/workflows/backend-tests.yml | 3 ++- plugin/openai/chat_completion.go | 4 ++-- plugin/openai/text_completion.go | 4 ++-- plugin/storage/s3/s3.go | 2 +- server/common.go | 4 ++-- server/rss.go | 4 ++-- server/system.go | 2 +- store/db/migration_history.go | 2 +- store/idp.go | 8 +++++--- store/memo.go | 8 ++++---- store/memo_organizer.go | 2 +- store/memo_resource.go | 6 +++--- store/resource.go | 16 ++++++++-------- store/shortcut.go | 6 +++--- store/storage.go | 8 ++++---- store/system_setting.go | 2 +- store/tag.go | 4 ++-- store/user.go | 4 ++-- store/user_setting.go | 2 +- 19 files changed, 47 insertions(+), 44 deletions(-) diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml index ce87f186..186352b4 100644 --- a/.github/workflows/backend-tests.yml +++ b/.github/workflows/backend-tests.yml @@ -23,7 +23,8 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - args: -v + version: v1.52.0 + args: -v --timeout=3m skip-cache: true go-tests: diff --git a/plugin/openai/chat_completion.go b/plugin/openai/chat_completion.go index 9e72d681..d9b94e29 100644 --- a/plugin/openai/chat_completion.go +++ b/plugin/openai/chat_completion.go @@ -19,7 +19,7 @@ type ChatCompletionChoice struct { } type ChatCompletionResponse struct { - Error interface{} `json:"error"` + Error any `json:"error"` Model string `json:"model"` Choices []ChatCompletionChoice `json:"choices"` } @@ -33,7 +33,7 @@ func PostChatCompletion(messages []ChatCompletionMessage, apiKey string, apiHost return "", err } - values := map[string]interface{}{ + values := map[string]any{ "model": "gpt-3.5-turbo", "messages": messages, "max_tokens": 2000, diff --git a/plugin/openai/text_completion.go b/plugin/openai/text_completion.go index be7846ae..4e1d3321 100644 --- a/plugin/openai/text_completion.go +++ b/plugin/openai/text_completion.go @@ -14,7 +14,7 @@ type TextCompletionChoice struct { } type TextCompletionResponse struct { - Error interface{} `json:"error"` + Error any `json:"error"` Model string `json:"model"` Choices []TextCompletionChoice `json:"choices"` } @@ -28,7 +28,7 @@ func PostTextCompletion(prompt string, apiKey string, apiHost string) (string, e return "", err } - values := map[string]interface{}{ + values := map[string]any{ "model": "gpt-3.5-turbo", "prompt": prompt, "temperature": 0.5, diff --git a/plugin/storage/s3/s3.go b/plugin/storage/s3/s3.go index 5ab103fe..87801224 100644 --- a/plugin/storage/s3/s3.go +++ b/plugin/storage/s3/s3.go @@ -28,7 +28,7 @@ type Client struct { } func NewClient(ctx context.Context, config *Config) (*Client, error) { - resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { + resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) { return aws.Endpoint{ URL: config.EndPoint, SigningRegion: config.Region, diff --git a/server/common.go b/server/common.go index 4aabe5de..6a15ffa5 100644 --- a/server/common.go +++ b/server/common.go @@ -9,10 +9,10 @@ import ( ) type response struct { - Data interface{} `json:"data"` + Data any `json:"data"` } -func composeResponse(data interface{}) response { +func composeResponse(data any) response { return response{ Data: data, } diff --git a/server/rss.go b/server/rss.go index e77602ee..88d4dc4d 100644 --- a/server/rss.go +++ b/server/rss.go @@ -135,14 +135,14 @@ func getSystemCustomizedProfile(ctx context.Context, s *Server) (api.CustomizedP continue } - var value interface{} + var value any err := json.Unmarshal([]byte(systemSetting.Value), &value) if err != nil { return api.CustomizedProfile{}, err } if systemSetting.Name == api.SystemSettingCustomizedProfileName { - valueMap := value.(map[string]interface{}) + valueMap := value.(map[string]any) systemStatus.CustomizedProfile = api.CustomizedProfile{} if v := valueMap["name"]; v != nil { systemStatus.CustomizedProfile.Name = v.(string) diff --git a/server/system.go b/server/system.go index 0574ee6f..d1fc53ab 100644 --- a/server/system.go +++ b/server/system.go @@ -63,7 +63,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) { continue } - var baseValue interface{} + var baseValue any err := json.Unmarshal([]byte(systemSetting.Value), &baseValue) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting value").SetInternal(err) diff --git a/store/db/migration_history.go b/store/db/migration_history.go index 5906e524..472bfb53 100644 --- a/store/db/migration_history.go +++ b/store/db/migration_history.go @@ -54,7 +54,7 @@ func (db *DB) UpsertMigrationHistory(ctx context.Context, upsert *MigrationHisto } func findMigrationHistoryList(ctx context.Context, tx *sql.Tx, find *MigrationHistoryFind) ([]*MigrationHistory, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.Version; v != nil { where, args = append(where, "version = ?"), append(args, *v) diff --git a/store/idp.go b/store/idp.go index 9958757b..c444b8fb 100644 --- a/store/idp.go +++ b/store/idp.go @@ -157,7 +157,7 @@ func (s *Store) UpdateIdentityProvider(ctx context.Context, update *UpdateIdenti } defer tx.Rollback() - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := update.Name; v != nil { set, args = append(set, "name = ?"), append(args, *v) } @@ -220,7 +220,7 @@ func (s *Store) DeleteIdentityProvider(ctx context.Context, delete *DeleteIdenti } defer tx.Rollback() - where, args := []string{"id = ?"}, []interface{}{delete.ID} + where, args := []string{"id = ?"}, []any{delete.ID} stmt := `DELETE FROM idp WHERE ` + strings.Join(where, " AND ") result, err := tx.ExecContext(ctx, stmt, args...) if err != nil { @@ -242,7 +242,7 @@ func (s *Store) DeleteIdentityProvider(ctx context.Context, delete *DeleteIdenti } func listIdentityProviders(ctx context.Context, tx *sql.Tx, find *FindIdentityProviderMessage) ([]*IdentityProviderMessage, error) { - where, args := []string{"TRUE"}, []interface{}{} + where, args := []string{"TRUE"}, []any{} if v := find.ID; v != nil { where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v) } @@ -289,8 +289,10 @@ func listIdentityProviders(ctx context.Context, tx *sql.Tx, find *FindIdentityPr } identityProviderMessages = append(identityProviderMessages, &identityProviderMessage) } + if err := rows.Err(); err != nil { return nil, FormatError(err) } + return identityProviderMessages, nil } diff --git a/store/memo.go b/store/memo.go index f1eba20d..448cecde 100644 --- a/store/memo.go +++ b/store/memo.go @@ -193,7 +193,7 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *api.MemoDelete) error { func createMemoRaw(ctx context.Context, tx *sql.Tx, create *api.MemoCreate) (*memoRaw, error) { set := []string{"creator_id", "content", "visibility"} - args := []interface{}{create.CreatorID, create.Content, create.Visibility} + args := []any{create.CreatorID, create.Content, create.Visibility} placeholder := []string{"?", "?", "?"} if v := create.CreatedTs; v != nil { @@ -224,7 +224,7 @@ func createMemoRaw(ctx context.Context, tx *sql.Tx, create *api.MemoCreate) (*me } func patchMemoRaw(ctx context.Context, tx *sql.Tx, patch *api.MemoPatch) (*memoRaw, error) { - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := patch.CreatedTs; v != nil { set, args = append(set, "created_ts = ?"), append(args, *v) @@ -267,7 +267,7 @@ func patchMemoRaw(ctx context.Context, tx *sql.Tx, patch *api.MemoPatch) (*memoR } func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*memoRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.ID; v != nil { where, args = append(where, "memo.id = ?"), append(args, *v) @@ -352,7 +352,7 @@ func findMemoRawList(ctx context.Context, tx *sql.Tx, find *api.MemoFind) ([]*me } func deleteMemo(ctx context.Context, tx *sql.Tx, delete *api.MemoDelete) error { - where, args := []string{"id = ?"}, []interface{}{delete.ID} + where, args := []string{"id = ?"}, []any{delete.ID} stmt := `DELETE FROM memo WHERE ` + strings.Join(where, " AND ") result, err := tx.ExecContext(ctx, stmt, args...) diff --git a/store/memo_organizer.go b/store/memo_organizer.go index 104dd2b7..844ba27e 100644 --- a/store/memo_organizer.go +++ b/store/memo_organizer.go @@ -148,7 +148,7 @@ func upsertMemoOrganizer(ctx context.Context, tx *sql.Tx, upsert *api.MemoOrgani } func deleteMemoOrganizer(ctx context.Context, tx *sql.Tx, delete *api.MemoOrganizerDelete) error { - where, args := []string{}, []interface{}{} + where, args := []string{}, []any{} if v := delete.MemoID; v != nil { where, args = append(where, "memo_id = ?"), append(args, *v) diff --git a/store/memo_resource.go b/store/memo_resource.go index 5491ddc6..92fe37de 100644 --- a/store/memo_resource.go +++ b/store/memo_resource.go @@ -108,7 +108,7 @@ func (s *Store) DeleteMemoResource(ctx context.Context, delete *api.MemoResource } func findMemoResourceList(ctx context.Context, tx *sql.Tx, find *api.MemoResourceFind) ([]*memoResourceRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.MemoID; v != nil { where, args = append(where, "memo_id = ?"), append(args, *v) @@ -157,7 +157,7 @@ func findMemoResourceList(ctx context.Context, tx *sql.Tx, find *api.MemoResourc func upsertMemoResource(ctx context.Context, tx *sql.Tx, upsert *api.MemoResourceUpsert) (*memoResourceRaw, error) { set := []string{"memo_id", "resource_id"} - args := []interface{}{upsert.MemoID, upsert.ResourceID} + args := []any{upsert.MemoID, upsert.ResourceID} placeholder := []string{"?", "?"} if v := upsert.UpdatedTs; v != nil { @@ -188,7 +188,7 @@ func upsertMemoResource(ctx context.Context, tx *sql.Tx, upsert *api.MemoResourc } func deleteMemoResource(ctx context.Context, tx *sql.Tx, delete *api.MemoResourceDelete) error { - where, args := []string{}, []interface{}{} + where, args := []string{}, []any{} if v := delete.MemoID; v != nil { where, args = append(where, "memo_id = ?"), append(args, *v) diff --git a/store/resource.go b/store/resource.go index 351c11b2..57f33a49 100644 --- a/store/resource.go +++ b/store/resource.go @@ -192,7 +192,7 @@ func (s *Store) PatchResource(ctx context.Context, patch *api.ResourcePatch) (*a func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.ResourceCreate) (*resourceRaw, error) { fields := []string{"filename", "blob", "external_link", "type", "size", "creator_id"} - values := []interface{}{create.Filename, create.Blob, create.ExternalLink, create.Type, create.Size, create.CreatorID} + values := []any{create.Filename, create.Blob, create.ExternalLink, create.Type, create.Size, create.CreatorID} placeholders := []string{"?", "?", "?", "?", "?", "?"} if s.profile.IsDev() { fields = append(fields, "visibility") @@ -208,7 +208,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api. RETURNING id, ` + strings.Join(fields, ",") + `, created_ts, updated_ts ` var resourceRaw resourceRaw - dests := []interface{}{ + dests := []any{ &resourceRaw.ID, &resourceRaw.Filename, &resourceRaw.Blob, @@ -220,7 +220,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api. if s.profile.IsDev() { dests = append(dests, &resourceRaw.Visibility) } - dests = append(dests, []interface{}{&resourceRaw.CreatedTs, &resourceRaw.UpdatedTs}...) + dests = append(dests, []any{&resourceRaw.CreatedTs, &resourceRaw.UpdatedTs}...) if err := tx.QueryRowContext(ctx, query, values...).Scan(dests...); err != nil { return nil, FormatError(err) } @@ -229,7 +229,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api. } func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (*resourceRaw, error) { - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := patch.UpdatedTs; v != nil { set, args = append(set, "updated_ts = ?"), append(args, *v) @@ -256,7 +256,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re WHERE id = ? RETURNING ` + strings.Join(fields, ", ") var resourceRaw resourceRaw - dests := []interface{}{ + dests := []any{ &resourceRaw.ID, &resourceRaw.Filename, &resourceRaw.ExternalLink, @@ -277,7 +277,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re } func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) ([]*resourceRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.ID; v != nil { where, args = append(where, "resource.id = ?"), append(args, *v) @@ -319,7 +319,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api. resourceRawList := make([]*resourceRaw, 0) for rows.Next() { var resourceRaw resourceRaw - dests := []interface{}{ + dests := []any{ &resourceRaw.LinkedMemoAmount, &resourceRaw.ID, &resourceRaw.Filename, @@ -350,7 +350,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api. } func deleteResource(ctx context.Context, tx *sql.Tx, delete *api.ResourceDelete) error { - where, args := []string{"id = ?"}, []interface{}{delete.ID} + where, args := []string{"id = ?"}, []any{delete.ID} stmt := `DELETE FROM resource WHERE ` + strings.Join(where, " AND ") result, err := tx.ExecContext(ctx, stmt, args...) diff --git a/store/shortcut.go b/store/shortcut.go index 5348097f..d6b81279 100644 --- a/store/shortcut.go +++ b/store/shortcut.go @@ -180,7 +180,7 @@ func createShortcut(ctx context.Context, tx *sql.Tx, create *api.ShortcutCreate) } func patchShortcut(ctx context.Context, tx *sql.Tx, patch *api.ShortcutPatch) (*shortcutRaw, error) { - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := patch.UpdatedTs; v != nil { set, args = append(set, "updated_ts = ?"), append(args, *v) @@ -220,7 +220,7 @@ func patchShortcut(ctx context.Context, tx *sql.Tx, patch *api.ShortcutPatch) (* } func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ([]*shortcutRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.ID; v != nil { where, args = append(where, "id = ?"), append(args, *v) @@ -277,7 +277,7 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ( } func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete) error { - where, args := []string{}, []interface{}{} + where, args := []string{}, []any{} if v := delete.ID; v != nil { where, args = append(where, "id = ?"), append(args, *v) diff --git a/store/storage.go b/store/storage.go index 9bc777b4..0b560aec 100644 --- a/store/storage.go +++ b/store/storage.go @@ -125,7 +125,7 @@ func (s *Store) DeleteStorage(ctx context.Context, delete *api.StorageDelete) er func createStorageRaw(ctx context.Context, tx *sql.Tx, create *api.StorageCreate) (*storageRaw, error) { set := []string{"name", "type", "config"} - args := []interface{}{create.Name, create.Type} + args := []any{create.Name, create.Type} placeholder := []string{"?", "?", "?"} var configBytes []byte @@ -162,7 +162,7 @@ func createStorageRaw(ctx context.Context, tx *sql.Tx, create *api.StorageCreate } func patchStorageRaw(ctx context.Context, tx *sql.Tx, patch *api.StoragePatch) (*storageRaw, error) { - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := patch.Name; v != nil { set, args = append(set, "name = ?"), append(args, *v) } @@ -213,7 +213,7 @@ func patchStorageRaw(ctx context.Context, tx *sql.Tx, patch *api.StoragePatch) ( } func findStorageRawList(ctx context.Context, tx *sql.Tx, find *api.StorageFind) ([]*storageRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.ID; v != nil { where, args = append(where, "id = ?"), append(args, *v) @@ -269,7 +269,7 @@ func findStorageRawList(ctx context.Context, tx *sql.Tx, find *api.StorageFind) } func deleteStorage(ctx context.Context, tx *sql.Tx, delete *api.StorageDelete) error { - where, args := []string{"id = ?"}, []interface{}{delete.ID} + where, args := []string{"id = ?"}, []any{delete.ID} stmt := `DELETE FROM storage WHERE ` + strings.Join(where, " AND ") result, err := tx.ExecContext(ctx, stmt, args...) diff --git a/store/system_setting.go b/store/system_setting.go index e7792163..f3fced79 100644 --- a/store/system_setting.go +++ b/store/system_setting.go @@ -113,7 +113,7 @@ func upsertSystemSetting(ctx context.Context, tx *sql.Tx, upsert *api.SystemSett } func findSystemSettingList(ctx context.Context, tx *sql.Tx, find *api.SystemSettingFind) ([]*systemSettingRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if find.Name.String() != "" { where, args = append(where, "name = ?"), append(args, find.Name.String()) } diff --git a/store/tag.go b/store/tag.go index ff40f61e..0144a9d4 100644 --- a/store/tag.go +++ b/store/tag.go @@ -104,7 +104,7 @@ func upsertTag(ctx context.Context, tx *sql.Tx, upsert *api.TagUpsert) (*tagRaw, } func findTagList(ctx context.Context, tx *sql.Tx, find *api.TagFind) ([]*tagRaw, error) { - where, args := []string{"creator_id = ?"}, []interface{}{find.CreatorID} + where, args := []string{"creator_id = ?"}, []any{find.CreatorID} query := ` SELECT @@ -141,7 +141,7 @@ func findTagList(ctx context.Context, tx *sql.Tx, find *api.TagFind) ([]*tagRaw, } func deleteTag(ctx context.Context, tx *sql.Tx, delete *api.TagDelete) error { - where, args := []string{"name = ?", "creator_id = ?"}, []interface{}{delete.Name, delete.CreatorID} + where, args := []string{"name = ?", "creator_id = ?"}, []any{delete.Name, delete.CreatorID} stmt := `DELETE FROM tag WHERE ` + strings.Join(where, " AND ") result, err := tx.ExecContext(ctx, stmt, args...) diff --git a/store/user.go b/store/user.go index 6758aa0a..a7e5ba22 100644 --- a/store/user.go +++ b/store/user.go @@ -216,7 +216,7 @@ func createUser(ctx context.Context, tx *sql.Tx, create *api.UserCreate) (*userR } func patchUser(ctx context.Context, tx *sql.Tx, patch *api.UserPatch) (*userRaw, error) { - set, args := []string{}, []interface{}{} + set, args := []string{}, []any{} if v := patch.UpdatedTs; v != nil { set, args = append(set, "updated_ts = ?"), append(args, *v) @@ -272,7 +272,7 @@ func patchUser(ctx context.Context, tx *sql.Tx, patch *api.UserPatch) (*userRaw, } func findUserList(ctx context.Context, tx *sql.Tx, find *api.UserFind) ([]*userRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.ID; v != nil { where, args = append(where, "id = ?"), append(args, *v) diff --git a/store/user_setting.go b/store/user_setting.go index 2782defd..641574f4 100644 --- a/store/user_setting.go +++ b/store/user_setting.go @@ -118,7 +118,7 @@ func upsertUserSetting(ctx context.Context, tx *sql.Tx, upsert *api.UserSettingU } func findUserSettingList(ctx context.Context, tx *sql.Tx, find *api.UserSettingFind) ([]*userSettingRaw, error) { - where, args := []string{"1 = 1"}, []interface{}{} + where, args := []string{"1 = 1"}, []any{} if v := find.Key.String(); v != "" { where, args = append(where, "key = ?"), append(args, v)