# Server Development ## Prerequisites - Go 1.26.2, pinned in `mise.toml` - `mise` for installing the pinned toolchain ```bash mise install ``` ## Build ```bash go build ./... go build -o mygo . ``` ## Test ```bash go test ./... go test -v -run TestName ./internal/... go test -race ./internal/repository ./internal/service ./internal/server ``` ## Format and Static Analysis ```bash go fmt ./... go vet ./... ``` ## Dependencies Run module cleanup after adding or removing imports: ```bash go mod tidy ``` ## Repository Review Use `$mygo-api-repo-review` for evidence-based architecture, design, security, resilience, data-consistency, performance, and implementation audits. | Mode | Scope | |------|-------| | `diff` | Workspace, including relevant untracked files, compared with `HEAD` | | `main` | Workspace compared with the merge base of `HEAD` and local `main` | | `full` | Complete repository | Reviews are read-only unless the user also requests fixes. A mode can target a path, Go package, or logical component. ## Configuration The server reads `config.yaml` from the working directory when present. Environment variables use the `MYGO_` prefix and underscores, for example `MYGO_SERVER_PORT` and `MYGO_JWT_SECRET`. ```yaml server: host: 0.0.0.0 port: 10086 database: driver: sqlite3 sqlite: path: data/mygo.db storage: driver: local max_upload_size: 0 local: path: data/files jwt: secret: dev-secret-do-not-use-in-production access_ttl: 15m refresh_ttl: 168h log: level: info file_path: "" file_level: debug ``` | Setting | Behavior | |---------|----------| | `database.driver` | Selects `sqlite3` or `postgres` | | `storage.max_upload_size` | `0` allows any upload size; a positive byte count enables request and service limits | | `jwt.secret` | Signs access and refresh tokens | | `log.level` | Sets stderr logging to `debug`, `info`, `warn`, or `error` | | `log.file_path` | Enables an additional text log file when set | | `log.file_level` | Sets the file log level independently | PostgreSQL uses the `database.postgres` host, port, user, password, database name, and SSL mode fields defined in `internal/config`. The SQLite connector preserves configured DSN parameters and sets `_txlock=immediate`. This setting establishes the transaction behavior required by hierarchy and refresh-session commands. The default JWT secret is a development placeholder. Configuration loading replaces it with a random in-memory secret for the current process. Set a stable secret for multi-instance deployments and tokens that must survive a restart.