Commit 7cc2df92 authored by Johnny's avatar Johnny

chore: fix linter

parent 3d1c1977
...@@ -12,23 +12,17 @@ import ( ...@@ -12,23 +12,17 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/usememos/memos/internal/profile" "github.com/usem fmt.Println()
fmt.Printf("Documentation: %s\n", "https://usememos.com")
fmt.Printf("Source code: %s\n", "https://github.com/usememos/memos")
fmt.Println("\nHappy note-taking!")/memos/internal/profile"
"github.com/usememos/memos/internal/version" "github.com/usememos/memos/internal/version"
"github.com/usememos/memos/server" "github.com/usememos/memos/server"
"github.com/usememos/memos/store" "github.com/usememos/memos/store"
"github.com/usememos/memos/store/db" "github.com/usememos/memos/store/db"
) )
const (
greetingBanner = `
███╗ ███╗███████╗███╗ ███╗ ██████╗ ███████╗
████╗ ████║██╔════╝████╗ ████║██╔═══██╗██╔════╝
██╔████╔██║█████╗ ██╔████╔██║██║ ██║███████╗
██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║██║ ██║╚════██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║╚██████╔╝███████║
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
`
)
var ( var (
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
...@@ -146,38 +140,37 @@ func init() { ...@@ -146,38 +140,37 @@ func init() {
} }
func printGreetings(profile *profile.Profile) { func printGreetings(profile *profile.Profile) {
fmt.Printf("Memos %s started successfully!\n", profile.Version)
if profile.IsDev() { if profile.IsDev() {
println("Development mode is enabled") fmt.Fprintf(os.Stderr, "Development mode is enabled\n")
println("DSN: ", profile.DSN) if profile.DSN != "" {
} fmt.Fprintf(os.Stderr, "Database: %s\n", profile.DSN)
fmt.Printf(`--- }
Server profile }
version: %s
data: %s // Server information
addr: %s fmt.Printf("Data directory: %s\n", profile.Data)
port: %d fmt.Printf("Database driver: %s\n", profile.Driver)
unix-sock: %s fmt.Printf("Mode: %s\n", profile.Mode)
mode: %s
driver: %s // Connection information
---
`, profile.Version, profile.Data, profile.Addr, profile.Port, profile.UNIXSock, profile.Mode, profile.Driver)
print(greetingBanner)
if len(profile.UNIXSock) == 0 { if len(profile.UNIXSock) == 0 {
if len(profile.Addr) == 0 { if len(profile.Addr) == 0 {
fmt.Printf("Version %s has been started on port %d\n", profile.Version, profile.Port) fmt.Printf("Server running on port %d\n", profile.Port)
fmt.Printf("Access your memos at: http://localhost:%d\n", profile.Port)
} else { } else {
fmt.Printf("Version %s has been started on address '%s' and port %d\n", profile.Version, profile.Addr, profile.Port) fmt.Printf("Server running on %s:%d\n", profile.Addr, profile.Port)
fmt.Printf("Access your memos at: http://%s:%d\n", profile.Addr, profile.Port)
} }
} else { } else {
fmt.Printf("Version %s has been started on unix socket %s\n", profile.Version, profile.UNIXSock) fmt.Printf("Server running on unix socket: %s\n", profile.UNIXSock)
} }
fmt.Printf(`---
See more in: fmt.Println()
👉Website: %s fmt.Printf("� Documentation: %s\n", "https://usememos.com")
👉GitHub: %s fmt.Printf("💻 Source code: %s\n", "https://github.com/usememos/memos")
--- fmt.Println("\n✨ Happy note-taking!")
`, "https://usememos.com", "https://github.com/usememos/memos")
} }
func main() { func main() {
......
package util package util //nolint:revive // util is an appropriate package name for utility functions
import ( import (
"testing" "testing"
......
...@@ -420,6 +420,8 @@ func parseDescriptor(descriptor string, loc *time.Location) (Schedule, error) { ...@@ -420,6 +420,8 @@ func parseDescriptor(descriptor string, loc *time.Location) (Schedule, error) {
Dow: all(dow), Dow: all(dow),
Location: loc, Location: loc,
}, nil }, nil
default:
// Continue to check @every prefix below
} }
const every = "@every " const every = "@every "
......
...@@ -45,6 +45,8 @@ func (c *CommonSQLConverter) ConvertExprToSQL(ctx *ConvertContext, expr *exprv1. ...@@ -45,6 +45,8 @@ func (c *CommonSQLConverter) ConvertExprToSQL(ctx *ConvertContext, expr *exprv1.
return c.handleInOperator(ctx, v.CallExpr) return c.handleInOperator(ctx, v.CallExpr)
case "contains": case "contains":
return c.handleContainsOperator(ctx, v.CallExpr) return c.handleContainsOperator(ctx, v.CallExpr)
default:
return errors.Errorf("unsupported call expression function: %s", v.CallExpr.Function)
} }
} else if v, ok := expr.ExprKind.(*exprv1.Expr_IdentExpr); ok { } else if v, ok := expr.ExprKind.(*exprv1.Expr_IdentExpr); ok {
return c.handleIdentifier(ctx, v.IdentExpr) return c.handleIdentifier(ctx, v.IdentExpr)
...@@ -144,9 +146,9 @@ func (c *CommonSQLConverter) handleComparisonOperator(ctx *ConvertContext, callE ...@@ -144,9 +146,9 @@ func (c *CommonSQLConverter) handleComparisonOperator(ctx *ConvertContext, callE
return c.handlePinnedComparison(ctx, operator, value) return c.handlePinnedComparison(ctx, operator, value)
case "has_task_list", "has_link", "has_code", "has_incomplete_tasks": case "has_task_list", "has_link", "has_code", "has_incomplete_tasks":
return c.handleBooleanComparison(ctx, identifier, operator, value) return c.handleBooleanComparison(ctx, identifier, operator, value)
default:
return errors.Errorf("unsupported identifier in comparison: %s", identifier)
} }
return nil
} }
func (c *CommonSQLConverter) handleSizeComparison(ctx *ConvertContext, callExpr *exprv1.Expr_Call, sizeCall *exprv1.Expr_Call) error { func (c *CommonSQLConverter) handleSizeComparison(ctx *ConvertContext, callExpr *exprv1.Expr_Call, sizeCall *exprv1.Expr_Call) error {
...@@ -567,6 +569,8 @@ func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field, ...@@ -567,6 +569,8 @@ func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field,
jsonPath = "$.property.hasCode" jsonPath = "$.property.hasCode"
case "has_incomplete_tasks": case "has_incomplete_tasks":
jsonPath = "$.property.hasIncompleteTasks" jsonPath = "$.property.hasIncompleteTasks"
default:
return errors.Errorf("unsupported boolean field: %s", field)
} }
// Special handling for SQLite based on field // Special handling for SQLite based on field
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/activity_service.proto // source: api/v1/activity_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/attachment_service.proto // source: api/v1/attachment_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/auth_service.proto // source: api/v1/auth_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/common.proto // source: api/v1/common.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/idp_service.proto // source: api/v1/idp_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/inbox_service.proto // source: api/v1/inbox_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/markdown_service.proto // source: api/v1/markdown_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/memo_service.proto // source: api/v1/memo_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/shortcut_service.proto // source: api/v1/shortcut_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/user_service.proto // source: api/v1/user_service.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: api/v1/workspace_service.proto // source: api/v1/workspace_service.proto
......
This diff is collapsed.
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/activity.proto // source: store/activity.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/attachment.proto // source: store/attachment.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/idp.proto // source: store/idp.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/inbox.proto // source: store/inbox.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/memo.proto // source: store/memo.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/user_setting.proto // source: store/user_setting.proto
......
// Code generated by protoc-gen-go. DO NOT EDIT. // Code generated by protoc-gen-go. DO NOT EDIT.
// versions: // versions:
// protoc-gen-go v1.36.7 // protoc-gen-go v1.36.8
// protoc (unknown) // protoc (unknown)
// source: store/workspace_setting.proto // source: store/workspace_setting.proto
......
...@@ -582,8 +582,9 @@ func replaceFilenameWithPathTemplate(path, filename string) string { ...@@ -582,8 +582,9 @@ func replaceFilenameWithPathTemplate(path, filename string) string {
return fmt.Sprintf("%02d", t.Second()) return fmt.Sprintf("%02d", t.Second())
case "{uuid}": case "{uuid}":
return util.GenUUID() return util.GenUUID()
} default:
return s return s
}
}) })
return path return path
} }
......
...@@ -162,7 +162,7 @@ func TestClientInfoExamples(t *testing.T) { ...@@ -162,7 +162,7 @@ func TestClientInfoExamples(t *testing.T) {
t.Logf("Device Type: %s", clientInfo.DeviceType) t.Logf("Device Type: %s", clientInfo.DeviceType)
t.Logf("Operating System: %s", clientInfo.Os) t.Logf("Operating System: %s", clientInfo.Os)
t.Logf("Browser: %s", clientInfo.Browser) t.Logf("Browser: %s", clientInfo.Browser)
t.Logf("---") t.Log("---")
// Ensure all fields are populated // Ensure all fields are populated
if clientInfo.DeviceType == "" { if clientInfo.DeviceType == "" {
......
...@@ -82,6 +82,8 @@ func (s *APIV1Service) UpdateIdentityProvider(ctx context.Context, request *v1pb ...@@ -82,6 +82,8 @@ func (s *APIV1Service) UpdateIdentityProvider(ctx context.Context, request *v1pb
update.IdentifierFilter = &request.IdentityProvider.IdentifierFilter update.IdentifierFilter = &request.IdentityProvider.IdentifierFilter
case "config": case "config":
update.Config = convertIdentityProviderConfigToStore(request.IdentityProvider.Type, request.IdentityProvider.Config) update.Config = convertIdentityProviderConfigToStore(request.IdentityProvider.Type, request.IdentityProvider.Config)
default:
// Ignore unsupported fields
} }
} }
......
...@@ -405,6 +405,8 @@ func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.Upda ...@@ -405,6 +405,8 @@ func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.Upda
updatedGeneral.Theme = incomingGeneral.Theme updatedGeneral.Theme = incomingGeneral.Theme
case "locale": case "locale":
updatedGeneral.Locale = incomingGeneral.Locale updatedGeneral.Locale = incomingGeneral.Locale
default:
// Ignore unsupported fields
} }
} }
...@@ -899,6 +901,8 @@ func (s *APIV1Service) UpdateUserWebhook(ctx context.Context, request *v1pb.Upda ...@@ -899,6 +901,8 @@ func (s *APIV1Service) UpdateUserWebhook(ctx context.Context, request *v1pb.Upda
} }
case "display_name": case "display_name":
updatedWebhook.Title = request.Webhook.DisplayName updatedWebhook.Title = request.Webhook.DisplayName
default:
// Ignore unsupported fields
} }
} }
} else { } else {
...@@ -1143,6 +1147,11 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, userID int32 ...@@ -1143,6 +1147,11 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, userID int32
Webhooks: []*v1pb.UserWebhook{}, Webhooks: []*v1pb.UserWebhook{},
}, },
} }
default:
// Default to general setting
setting.Value = &v1pb.UserSetting_GeneralSetting_{
GeneralSetting: getDefaultUserGeneralSetting(),
}
} }
return setting return setting
} }
...@@ -1223,6 +1232,11 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, userID int32 ...@@ -1223,6 +1232,11 @@ func convertUserSettingFromStore(storeSetting *storepb.UserSetting, userID int32
Webhooks: apiWebhooks, Webhooks: apiWebhooks,
}, },
} }
default:
// Default to general setting if unknown key
setting.Value = &v1pb.UserSetting_GeneralSetting_{
GeneralSetting: getDefaultUserGeneralSetting(),
}
} }
return setting return setting
......
...@@ -141,6 +141,8 @@ func convertWorkspaceSettingToStore(setting *v1pb.WorkspaceSetting) *storepb.Wor ...@@ -141,6 +141,8 @@ func convertWorkspaceSettingToStore(setting *v1pb.WorkspaceSetting) *storepb.Wor
workspaceSetting.Value = &storepb.WorkspaceSetting_MemoRelatedSetting{ workspaceSetting.Value = &storepb.WorkspaceSetting_MemoRelatedSetting{
MemoRelatedSetting: convertWorkspaceMemoRelatedSettingToStore(setting.GetMemoRelatedSetting()), MemoRelatedSetting: convertWorkspaceMemoRelatedSettingToStore(setting.GetMemoRelatedSetting()),
} }
default:
// Keep the default GeneralSetting value
} }
return workspaceSetting return workspaceSetting
} }
......
...@@ -31,30 +31,30 @@ func TestCacheBasicOperations(t *testing.T) { ...@@ -31,30 +31,30 @@ func TestCacheBasicOperations(t *testing.T) {
// Test Delete // Test Delete
cache.Delete(ctx, "key1") cache.Delete(ctx, "key1")
if _, ok := cache.Get(ctx, "key1"); ok { if _, ok := cache.Get(ctx, "key1"); ok {
t.Errorf("Key 'key1' should have been deleted") t.Error("Key 'key1' should have been deleted")
} }
// Test automatic expiration // Test automatic expiration
time.Sleep(150 * time.Millisecond) time.Sleep(150 * time.Millisecond)
if _, ok := cache.Get(ctx, "key1"); ok { if _, ok := cache.Get(ctx, "key1"); ok {
t.Errorf("Key 'key1' should have expired") t.Error("Key 'key1' should have expired")
} }
// key2 should still be valid (200ms TTL) // key2 should still be valid (200ms TTL)
if _, ok := cache.Get(ctx, "key2"); !ok { if _, ok := cache.Get(ctx, "key2"); !ok {
t.Errorf("Key 'key2' should still be valid") t.Error("Key 'key2' should still be valid")
} }
// Wait for key2 to expire // Wait for key2 to expire
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if _, ok := cache.Get(ctx, "key2"); ok { if _, ok := cache.Get(ctx, "key2"); ok {
t.Errorf("Key 'key2' should have expired") t.Error("Key 'key2' should have expired")
} }
// Test Clear // Test Clear
cache.Set(ctx, "key3", "value3") cache.Set(ctx, "key3", "value3")
cache.Clear(ctx) cache.Clear(ctx)
if _, ok := cache.Get(ctx, "key3"); ok { if _, ok := cache.Get(ctx, "key3"); ok {
t.Errorf("Cache should be empty after Clear()") t.Error("Cache should be empty after Clear()")
} }
} }
...@@ -98,15 +98,15 @@ func TestCacheEviction(t *testing.T) { ...@@ -98,15 +98,15 @@ func TestCacheEviction(t *testing.T) {
} }
if evictedCount == 0 { if evictedCount == 0 {
t.Errorf("No keys were evicted despite exceeding max items") t.Error("No keys were evicted despite exceeding max items")
} }
// The newer keys should still be present // The newer keys should still be present
if _, ok := cache.Get(ctx, "keyA"); !ok { if _, ok := cache.Get(ctx, "keyA"); !ok {
t.Errorf("Key 'keyA' should be in the cache") t.Error("Key 'keyA' should be in the cache")
} }
if _, ok := cache.Get(ctx, "keyB"); !ok { if _, ok := cache.Get(ctx, "keyB"); !ok {
t.Errorf("Key 'keyB' should be in the cache") t.Error("Key 'keyB' should be in the cache")
} }
} }
...@@ -193,7 +193,7 @@ func TestEvictionCallback(t *testing.T) { ...@@ -193,7 +193,7 @@ func TestEvictionCallback(t *testing.T) {
time.Sleep(10 * time.Millisecond) // Small delay to ensure callback processed time.Sleep(10 * time.Millisecond) // Small delay to ensure callback processed
evictedMu.Lock() evictedMu.Lock()
if evicted["key1"] != "value1" { if evicted["key1"] != "value1" {
t.Errorf("Eviction callback not triggered for manual deletion") t.Error("Eviction callback not triggered for manual deletion")
} }
evictedMu.Unlock() evictedMu.Unlock()
...@@ -203,7 +203,7 @@ func TestEvictionCallback(t *testing.T) { ...@@ -203,7 +203,7 @@ func TestEvictionCallback(t *testing.T) {
// Verify TTL expiration triggered callback // Verify TTL expiration triggered callback
evictedMu.Lock() evictedMu.Lock()
if evicted["key2"] != "value2" { if evicted["key2"] != "value2" {
t.Errorf("Eviction callback not triggered for TTL expiration") t.Error("Eviction callback not triggered for TTL expiration")
} }
evictedMu.Unlock() evictedMu.Unlock()
} }
...@@ -29,8 +29,9 @@ func (v Visibility) String() string { ...@@ -29,8 +29,9 @@ func (v Visibility) String() string {
return "PROTECTED" return "PROTECTED"
case Private: case Private:
return "PRIVATE" return "PRIVATE"
} default:
return "PRIVATE" return "PRIVATE"
}
} }
type Memo struct { type Memo struct {
......
...@@ -102,6 +102,8 @@ func (s *Store) Migrate(ctx context.Context) error { ...@@ -102,6 +102,8 @@ func (s *Store) Migrate(ctx context.Context) error {
if err := s.seed(ctx); err != nil { if err := s.seed(ctx); err != nil {
return errors.Wrap(err, "failed to seed") return errors.Wrap(err, "failed to seed")
} }
default:
// For other modes (like dev), no special migration handling needed
} }
return nil return nil
} }
......
...@@ -24,8 +24,9 @@ func (e Role) String() string { ...@@ -24,8 +24,9 @@ func (e Role) String() string {
return "ADMIN" return "ADMIN"
case RoleUser: case RoleUser:
return "USER" return "USER"
} default:
return "USER" return "USER"
}
} }
const ( const (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment