From 6b750cd34b43d7b56b4d466d8ebcc9492cc0471c Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Thu, 22 May 2025 07:23:18 +0300 Subject: [PATCH] Feat: add example config --- .gitignore | 1 + .golangci.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ config.example.toml | 11 +++++++++++ config/config.go | 1 - handlers/actions.go | 13 ------------- handlers/auth.go | 19 +++++++++---------- handlers/handlers.go | 28 ---------------------------- models/main.go | 1 + 8 files changed, 66 insertions(+), 52 deletions(-) create mode 100644 .golangci.yml create mode 100644 config.example.toml diff --git a/.gitignore b/.gitignore index cde8139..04107cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .aider* golias store.json +config.toml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d377c38 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,44 @@ +version: "2" +run: + concurrency: 2 + tests: false +linters: + default: none + enable: + - bodyclose + - errcheck + - fatcontext + - govet + - ineffassign + - noctx + - perfsprint + - prealloc + - staticcheck + - unused + settings: + funlen: + lines: 80 + statements: 50 + lll: + line-length: 80 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +issues: + max-issues-per-linter: 0 + max-same-issues: 0 +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/config.example.toml b/config.example.toml new file mode 100644 index 0000000..9b84f99 --- /dev/null +++ b/config.example.toml @@ -0,0 +1,11 @@ +BASE_URL = "https://localhost:3000" +SESSION_LIFETIME_SECONDS = 30000 +COOKIE_SECRET = "test" + +[SERVICE] +HOST = "localhost" +PORT = "3000" + +[LLM] +TOKEN = "" +URL = "https://api.deepseek.com/beta" diff --git a/config/config.go b/config/config.go index 416137d..6608d3e 100644 --- a/config/config.go +++ b/config/config.go @@ -10,7 +10,6 @@ type Config struct { ServerConfig ServerConfig `toml:"SERVICE"` BaseURL string `toml:"BASE_URL"` SessionLifetime int `toml:"SESSION_LIFETIME_SECONDS"` - DBURI string `toml:"DBURI"` CookieSecret string `toml:"COOKIE_SECRET"` LLMConfig LLMConfig `toml:"LLM"` } diff --git a/handlers/actions.go b/handlers/actions.go index 18ef302..17149b9 100644 --- a/handlers/actions.go +++ b/handlers/actions.go @@ -56,10 +56,6 @@ func removeRoom(roomID string) { } // context -func getRoomIDFromCtx(ctx context.Context) string { - id, _ := ctx.Value(models.CtxRoomIDKey).(string) - return id -} func getStateByCtx(ctx context.Context) (*models.UserState, error) { username, ok := ctx.Value(models.CtxUsernameKey).(string) @@ -74,15 +70,6 @@ func getStateByCtx(ctx context.Context) (*models.UserState, error) { return us, nil } -func saveStateByCtx(ctx context.Context, state *models.UserState) error { - username, ok := ctx.Value(models.CtxUsernameKey).(string) - if !ok { - log.Debug("no username in ctx") - return errors.New("no username in ctx") - } - return saveState(username, state) -} - func saveFullInfo(fi *models.FullInfo) error { // INFO: unfortunately working no transactions; so case are possible where first object is updated but the second is not if err := saveState(fi.State.Username, fi.State); err != nil { diff --git a/handlers/auth.go b/handlers/auth.go index 0507423..06628f9 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -1,12 +1,10 @@ package handlers import ( - "context" "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/json" - "errors" "fmt" "golias/models" "golias/utils" @@ -178,11 +176,12 @@ func cacheSetSession(key string, session *models.Session) error { return nil } -func updateRoomInSession(ctx context.Context, roomID string) (context.Context, error) { - s, ok := ctx.Value(models.CtxSessionKey).(*models.Session) - if !ok { - return context.TODO(), errors.New("failed to extract session from ctx") - } - s.CurrentRoom = roomID - return context.WithValue(ctx, "session", s), nil -} +// unused +// func updateRoomInSession(ctx context.Context, roomID string) (context.Context, error) { +// s, ok := ctx.Value(models.CtxSessionKey).(*models.Session) +// if !ok { +// return context.TODO(), errors.New("failed to extract session from ctx") +// } +// s.CurrentRoom = roomID +// return context.WithValue(ctx, "session", s), nil +// } diff --git a/handlers/handlers.go b/handlers/handlers.go index 2c65eba..409fd00 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -29,34 +29,6 @@ func init() { // go Notifier.Listen() } -var roundWords = map[string]string{ - "hamster": "blue", - "child": "red", - "wheel": "white", - "condition": "black", - "test": "white", - "ball": "blue", - "violin": "red", - "rat": "white", - "perplexity": "blue", - "notion": "red", - "guitar": "blue", - "ocean": "blue", - "moon": "blue", - "coffee": "blue", - "mountain": "blue", - "book": "blue", - "camera": "blue", - "apple": "red", - "fire": "red", - "rose": "red", - "sun": "red", - "cherry": "red", - "heart": "red", - "tomato": "red", - "cloud": "white", -} - func HandlePing(w http.ResponseWriter, r *http.Request) { w.Write([]byte("pong")) } diff --git a/models/main.go b/models/main.go index 8d89526..cd09bf5 100644 --- a/models/main.go +++ b/models/main.go @@ -236,6 +236,7 @@ func (rr *RoomReq) CreateRoom(creator string) *Room { CreatedAt: time.Now(), PlayerList: []string{creator}, CreatorName: creator, + BotMap: make(map[string]BotPlayer), } }