Documentation
¶
Index ¶
- func InitLogger()
- func IsDuplicateKey(err error) bool
- func MetricsMiddleware(next http.Handler) http.Handler
- func Migrate(db *sql.DB) error
- func MigrateDown(db *sql.DB) error
- func MigrateStatus(db *sql.DB) error
- func NewPool(ctx context.Context, databaseURL string, cfg *PoolConfig) (*pgxpool.Pool, error)
- func OpenDB(databaseURL string) (*sql.DB, error)
- func RateLimiter(requestsPerMinute int, _ time.Duration) func(http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func RequestIDFromContext(ctx context.Context) string
- func RequestLogger(next http.Handler) http.Handler
- func RunMigrations(ctx context.Context, pool *pgxpool.Pool) error
- func SecurityHeaders(cookieSecure bool) func(http.Handler) http.Handler
- type Config
- type LocalStorage
- type PoolConfig
- type S3Storage
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
func InitLogger()
InitLogger configures zerolog. When LOG_FORMAT=pretty (or LOG_PRETTY=true), uses colorized console output for development. Otherwise outputs JSON for production/log aggregation.
func IsDuplicateKey ¶
IsDuplicateKey returns true if err is a Postgres unique-violation (SQLSTATE 23505).
func MigrateDown ¶
func MigrateStatus ¶
func RateLimiter ¶ added in v0.7.0
RateLimiter returns middleware that enforces per-IP rate limiting. requestsPerMinute controls the sustained rate; window is unused but reserved for future burst tuning. Clients exceeding the limit receive 429 with a Retry-After header. Stale entries are cleaned up on access.
func RequestID ¶ added in v0.7.0
RequestID is a Chi-compatible middleware that reads X-Request-ID from the incoming request, or generates a UUID if absent. It sets the ID on the response header and in the request context.
func RequestIDFromContext ¶ added in v0.7.0
RequestIDFromContext returns the request ID stored in ctx, or "".
func RequestLogger ¶
RequestLogger is a Chi-compatible middleware that logs every request using zerolog. Logs method, path, status, duration, and remote IP.
Types ¶
type Config ¶
type Config struct {
DatabaseURL string
StoragePath string
ListenAddr string
DisableSignup bool
GitHubToken string
// EventRetentionDays controls how many days of skill_events to keep.
// Events older than this are purged on startup. 0 disables cleanup.
EventRetentionDays int
// ExternalScanCmd, when set, is an opt-in external security scanner command
// run over each skill on publish/import (Phase 2). The token "{dir}" is
// replaced with the skill directory and the command must emit SARIF on
// stdout, e.g. "gitleaks dir {dir} --report-format sarif --report-path
// /dev/stdout". Empty disables the feature.
ExternalScanCmd string
ExternalScanTimeout time.Duration
DBMaxConns int
DBMinConns int
DBMaxConnLifetime time.Duration
DBMaxConnIdleTime time.Duration
DBHealthCheckPeriod time.Duration
CORSOrigins string
LogLevel string
RateLimitAuth int
}
Config holds all runtime configuration for the skael server.
func LoadConfig ¶
LoadConfig reads configuration from environment variables. DATABASE_URL is required; returns an error if absent. STORAGE_PATH defaults to "./data/skills" (or "s3://bucket/prefix" for S3); LISTEN_ADDR defaults to ":8080". DISABLE_SIGNUP=true prevents new registrations.
type LocalStorage ¶ added in v0.5.0
type LocalStorage struct {
BasePath string
}
LocalStorage provides local filesystem storage for skill archive files.
func NewLocalStorage ¶ added in v0.5.0
func NewLocalStorage(basePath string) (*LocalStorage, error)
NewLocalStorage creates a LocalStorage rooted at basePath, creating the directory if it does not already exist.
func (*LocalStorage) Delete ¶ added in v0.5.0
func (s *LocalStorage) Delete(_ context.Context, name string) error
Delete removes the file stored under name (relative to BasePath).
func (*LocalStorage) Ping ¶ added in v0.6.0
func (s *LocalStorage) Ping(_ context.Context) error
Ping verifies the base path still exists and is a directory.
func (*LocalStorage) Read ¶ added in v0.5.0
func (s *LocalStorage) Read(_ context.Context, name string) (io.ReadCloser, error)
Read opens the file stored under name (relative to BasePath) for reading. The caller is responsible for closing the returned ReadCloser.
func (*LocalStorage) Write ¶ added in v0.5.0
Write stores the content from r under name (relative to BasePath). It uses an atomic write: content is first written to a .tmp file which is then renamed to the final destination, ensuring no partial files are visible. Returns the full path of the written file.
type PoolConfig ¶ added in v0.7.0
type PoolConfig struct {
MaxConns int
MinConns int
MaxConnLifetime time.Duration
MaxConnIdleTime time.Duration
HealthCheckPeriod time.Duration
}
PoolConfig holds optional pgxpool tuning parameters. A nil value keeps pgxpool's built-in defaults.
type S3Storage ¶ added in v0.5.0
type S3Storage struct {
// contains filtered or unexported fields
}
S3Storage stores archives in any S3-compatible object store.
type Storage ¶
type Storage interface {
// Write stores r under name and returns the stored key (name).
Write(ctx context.Context, name string, r io.Reader) (string, error)
// Read opens the blob stored under name; caller closes the ReadCloser.
Read(ctx context.Context, name string) (io.ReadCloser, error)
// Delete removes the blob stored under name.
Delete(ctx context.Context, name string) error
// Ping verifies the backing store is reachable (readiness checks).
Ping(ctx context.Context) error
}
Storage abstracts archive blob storage (local filesystem or object storage). Names are relative keys, e.g. "code-review/abc123.tar.gz".
func NewStorageFromConfig ¶ added in v0.5.0
NewStorageFromConfig builds the Storage backend selected by STORAGE_PATH: "s3://bucket/prefix" → S3; anything else → local filesystem.