Documentation
¶
Overview ¶
Package core defines the configuration types and shared interfaces for the go-core authentication module. Consuming applications build a Config struct and pass it to app.New.
Index ¶
- Variables
- func RunCoreMigrations(ctx context.Context, pool *pgxpool.Pool) error
- func RunMigrations(ctx context.Context, pool *pgxpool.Pool, migrationsDir string) error
- func ValidateConfig(cfg Config) error
- type AdminBrandingConfig
- type AdminConfig
- type CORSConfig
- type CacheStore
- type Config
- type DatabaseConfig
- type EmailConfig
- type EmailSender
- type GeoIPConfig
- type JWTConfig
- type MemoryCacheStore
- func (m *MemoryCacheStore) Close()
- func (m *MemoryCacheStore) Delete(_ context.Context, keys ...string) error
- func (m *MemoryCacheStore) Exists(_ context.Context, key string) (bool, error)
- func (m *MemoryCacheStore) Expire(_ context.Context, key string, ttl time.Duration) error
- func (m *MemoryCacheStore) Get(_ context.Context, key string) (string, error)
- func (m *MemoryCacheStore) HGet(_ context.Context, key, field string) (string, error)
- func (m *MemoryCacheStore) HGetAll(_ context.Context, key string) (map[string]string, error)
- func (m *MemoryCacheStore) HSet(_ context.Context, key string, fields map[string]any) error
- func (m *MemoryCacheStore) Increment(_ context.Context, key string, ttl time.Duration) (int64, error)
- func (m *MemoryCacheStore) Ping(_ context.Context) error
- func (m *MemoryCacheStore) SAdd(_ context.Context, key string, members ...string) error
- func (m *MemoryCacheStore) SMembers(_ context.Context, key string) ([]string, error)
- func (m *MemoryCacheStore) SRem(_ context.Context, key string, members ...string) error
- func (m *MemoryCacheStore) Scan(_ context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
- func (m *MemoryCacheStore) Set(_ context.Context, key string, value string, ttl time.Duration) error
- func (m *MemoryCacheStore) TTL(_ context.Context, key string) (time.Duration, error)
- type OIDCConfig
- type RedisCacheStore
- func (r *RedisCacheStore) Client() *redis.Client
- func (r *RedisCacheStore) Delete(ctx context.Context, keys ...string) error
- func (r *RedisCacheStore) Exists(ctx context.Context, key string) (bool, error)
- func (r *RedisCacheStore) Expire(ctx context.Context, key string, ttl time.Duration) error
- func (r *RedisCacheStore) Get(ctx context.Context, key string) (string, error)
- func (r *RedisCacheStore) HGet(ctx context.Context, key, field string) (string, error)
- func (r *RedisCacheStore) HGetAll(ctx context.Context, key string) (map[string]string, error)
- func (r *RedisCacheStore) HSet(ctx context.Context, key string, fields map[string]any) error
- func (r *RedisCacheStore) Increment(ctx context.Context, key string, ttl time.Duration) (int64, error)
- func (r *RedisCacheStore) Ping(ctx context.Context) error
- func (r *RedisCacheStore) SAdd(ctx context.Context, key string, members ...string) error
- func (r *RedisCacheStore) SMembers(ctx context.Context, key string) ([]string, error)
- func (r *RedisCacheStore) SRem(ctx context.Context, key string, members ...string) error
- func (r *RedisCacheStore) Scan(ctx context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
- func (r *RedisCacheStore) Set(ctx context.Context, key string, value string, ttl time.Duration) error
- func (r *RedisCacheStore) TTL(ctx context.Context, key string) (time.Duration, error)
- type RedisConfig
- type SMSConfig
- type SessionConfig
- type SocialConfig
- type WebAuthnConfig
Constants ¶
This section is empty.
Variables ¶
var ErrCacheKeyNotFound = errors.New("cache: key not found")
ErrCacheKeyNotFound is returned when a key does not exist.
Functions ¶
func RunCoreMigrations ¶
RunCoreMigrations applies all go-core built-in migrations from the embedded migrations directory. Consumers should call this before RunMigrations to ensure the core schema (users, sessions, etc.) exists.
func RunMigrations ¶
RunMigrations applies pending SQL migrations from the given directory on disk. It skips rollback files (*_rollback.sql) and down migration files (*.down.sql). Migrations are tracked in the schema_migrations table.
func ValidateConfig ¶
ValidateConfig checks that all required Config fields are set. Returns a descriptive error for the first missing or invalid field. Called by app.New() before any initialization or connections.
Types ¶
type AdminBrandingConfig ¶
type AdminBrandingConfig struct {
OrgName string
LogoURL string
PrimaryColor string
SecondaryColor string
BorderRadius string
SidebarColor string
SidebarTextColor string
}
AdminBrandingConfig customizes the admin dashboard appearance. All fields are optional — zero values produce the default Bootstrap look.
type AdminConfig ¶
type AdminConfig struct {
APIKey string
Email string
SessionTTL time.Duration
BaseURL string
AdminBasePath string // URL path prefix for admin GUI (default "/gui")
Branding AdminBrandingConfig
}
AdminConfig holds admin GUI / API settings.
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
ExposeHeaders []string
MaxAge time.Duration
AllowCredentials bool
}
CORSConfig holds Cross-Origin Resource Sharing settings.
type CacheStore ¶
type CacheStore interface {
// Key-value operations
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, value string, ttl time.Duration) error
Delete(ctx context.Context, keys ...string) error
Exists(ctx context.Context, key string) (bool, error)
// Counter operations (for rate limiting, brute force tracking)
Increment(ctx context.Context, key string, ttl time.Duration) (int64, error)
// Hash operations (for sessions)
HSet(ctx context.Context, key string, fields map[string]any) error
HGetAll(ctx context.Context, key string) (map[string]string, error)
HGet(ctx context.Context, key, field string) (string, error)
// Set operations (for session indexes)
SAdd(ctx context.Context, key string, members ...string) error
SMembers(ctx context.Context, key string) ([]string, error)
SRem(ctx context.Context, key string, members ...string) error
// TTL operations
Expire(ctx context.Context, key string, ttl time.Duration) error
TTL(ctx context.Context, key string) (time.Duration, error)
// Key scanning (for background jobs like session expiry detection)
Scan(ctx context.Context, cursor uint64, pattern string, count int64) (keys []string, nextCursor uint64, err error)
// Ping for health checks
Ping(ctx context.Context) error
}
CacheStore abstracts key-value and hash storage for tokens, sessions, and rate limiting.
type Config ¶
type Config struct {
Database DatabaseConfig
Redis *RedisConfig // nil = use in-memory store
JWT JWTConfig
Email *EmailConfig // nil = no email sending
CORS CORSConfig
OIDC OIDCConfig
WebAuthn WebAuthnConfig
SMS SMSConfig
Admin AdminConfig
Social SocialConfig
GeoIP GeoIPConfig
Session SessionConfig
MultiTenant bool
PublicURL string
FrontendURL string
AppName string
Port string
GinMode string
}
Config is the top-level configuration for the go-core module. Consuming applications construct this struct however they want (env vars, files, flags, etc.). The core module never reads environment variables itself.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config populated with sensible defaults that match the application's built-in Viper defaults.
type DatabaseConfig ¶
type DatabaseConfig struct {
Host string
Port int
User string
Password string
DBName string
SSLMode string
}
DatabaseConfig holds PostgreSQL connection parameters.
type EmailConfig ¶
type EmailConfig struct {
Host string
Port int
Username string
Password string
From string
UseTLS bool
}
EmailConfig holds SMTP / email sending settings. Set Config.Email to nil to disable all email sending.
type EmailSender ¶
type EmailSender interface {
Send(ctx context.Context, to, subject, htmlBody, textBody string) error
}
EmailSender abstracts email transport. The core handles template rendering; this interface handles the actual sending.
type GeoIPConfig ¶
type GeoIPConfig struct {
DBPath string
}
GeoIPConfig holds GeoIP database settings.
type MemoryCacheStore ¶
type MemoryCacheStore struct {
// contains filtered or unexported fields
}
MemoryCacheStore is a thread-safe in-memory implementation of CacheStore. Intended for development and testing only.
func NewMemoryCacheStore ¶
func NewMemoryCacheStore() *MemoryCacheStore
NewMemoryCacheStore creates a MemoryCacheStore and starts the background GC.
func (*MemoryCacheStore) Close ¶
func (m *MemoryCacheStore) Close()
Close stops the background GC goroutine.
func (*MemoryCacheStore) Delete ¶
func (m *MemoryCacheStore) Delete(_ context.Context, keys ...string) error
Delete removes one or more keys.
func (*MemoryCacheStore) Expire ¶
Expire sets the TTL on a key-value entry. Has no effect if the key does not exist.
func (*MemoryCacheStore) Get ¶
Get retrieves a string value. Returns ErrCacheKeyNotFound if absent or expired.
func (*MemoryCacheStore) HGet ¶
HGet returns a single hash field. Returns ErrCacheKeyNotFound if absent.
func (*MemoryCacheStore) Increment ¶
func (m *MemoryCacheStore) Increment(_ context.Context, key string, ttl time.Duration) (int64, error)
Increment atomically increments a counter. The existing TTL is preserved; if the key is new the provided ttl is applied.
func (*MemoryCacheStore) Ping ¶
func (m *MemoryCacheStore) Ping(_ context.Context) error
Ping always returns nil for the in-memory store.
func (*MemoryCacheStore) Scan ¶
func (m *MemoryCacheStore) Scan(_ context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
Scan iterates keys matching a glob pattern. The cursor is an index into sorted keys. Returns matching keys, the next cursor (0 when done), and any error.
type OIDCConfig ¶
type OIDCConfig struct {
Enabled bool
DefaultAppID string
IDTokenTTL time.Duration
AuthCodeTTL time.Duration
}
OIDCConfig holds OpenID Connect provider settings.
type RedisCacheStore ¶
type RedisCacheStore struct {
// contains filtered or unexported fields
}
RedisCacheStore implements CacheStore using a Redis client.
func NewRedisCacheStore ¶
func NewRedisCacheStore(cfg RedisConfig) (*RedisCacheStore, error)
NewRedisCacheStore creates a Redis client from cfg, pings it, and returns the store.
func (*RedisCacheStore) Client ¶
func (r *RedisCacheStore) Client() *redis.Client
Client returns the underlying *redis.Client for Redis-specific operations such as PubSub that cannot be abstracted behind CacheStore.
func (*RedisCacheStore) Delete ¶
func (r *RedisCacheStore) Delete(ctx context.Context, keys ...string) error
Delete removes one or more keys.
func (*RedisCacheStore) Get ¶
Get retrieves a string value by key. Returns ErrCacheKeyNotFound if key is absent.
func (*RedisCacheStore) HGet ¶
HGet returns a single field from a hash. Returns ErrCacheKeyNotFound if absent.
func (*RedisCacheStore) Increment ¶
func (r *RedisCacheStore) Increment(ctx context.Context, key string, ttl time.Duration) (int64, error)
Increment atomically increments a counter. If the key is new (value becomes 1), the TTL is set.
func (*RedisCacheStore) Ping ¶
func (r *RedisCacheStore) Ping(ctx context.Context) error
Ping checks the Redis connection.
func (*RedisCacheStore) Scan ¶
func (r *RedisCacheStore) Scan(ctx context.Context, cursor uint64, pattern string, count int64) ([]string, uint64, error)
Scan iterates keys matching a pattern. Returns matching keys, the next cursor, and any error.
type RedisConfig ¶
RedisConfig holds Redis connection parameters. Set Config.Redis to nil to use an in-memory store instead.
type SMSConfig ¶
type SMSConfig struct {
Provider string
TwilioAccountSID string
TwilioAuthToken string
TwilioFromNumber string
}
SMSConfig holds SMS provider credentials.
type SessionConfig ¶
type SessionConfig struct {
TrustedDeviceCookieSameSite string
GroupExpiryEnabled bool
GroupExpiryScanInterval time.Duration
GroupKeyspaceNotifEnabled bool
RedisNotifyKeyspaceEvents string // value of REDIS_NOTIFY_KEYSPACE_EVENTS for expiry service
}
SessionConfig holds session and trusted-device settings.
type SocialConfig ¶
SocialConfig holds OAuth2 social-login settings.
type WebAuthnConfig ¶
WebAuthnConfig holds WebAuthn / passkey relying-party settings.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package app provides the public entry point for the go-core authentication module.
|
Package app provides the public entry point for the go-core authentication module. |
|
cmd
|
|
|
api
command
|
|
|
migrate_oauth
command
|
|
|
setup
command
|
|
|
Package docs Code generated by swaggo/swag.
|
Package docs Code generated by swaggo/swag. |
|
examples
|
|
|
basic
command
|
|
|
internal
|
|
|
coreapp
Package coreapp provides the application entry point for go-core.
|
Package coreapp provides the application entry point for go-core. |
|
pkg
|
|
|
Package web provides the embedded admin GUI assets and HTML template renderer used by the go-core admin interface.
|
Package web provides the embedded admin GUI assets and HTML template renderer used by the go-core admin interface. |