mirror of
https://github.com/ThisTine/Snip.git
synced 2026-08-18 23:18:47 +07:00
feat: .env.example
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
# ── Storage ──────────────────────────────────────────────────────────────────
|
||||||
|
STORE=postgres
|
||||||
|
DATABASE_URL=postgres://snip:snip@localhost:5432/snip?sslmode=disable
|
||||||
|
|
||||||
|
# ── Redis ─────────────────────────────────────────────────────────────────────
|
||||||
|
REDIS_ADDR=localhost:6379
|
||||||
|
REDIS_PASSWORD=
|
||||||
|
REDIS_DB=0
|
||||||
|
# Namespace prefix for all Redis keys — set this when sharing a Redis instance
|
||||||
|
# with other apps, e.g. REDIS_KEY_PREFIX=snip: → keys look like snip:code:abc
|
||||||
|
REDIS_KEY_PREFIX=
|
||||||
|
|
||||||
|
# ── App ───────────────────────────────────────────────────────────────────────
|
||||||
|
PUBLIC_URL=http://localhost:8080
|
||||||
|
SHORT_DOMAIN=localhost:8080
|
||||||
|
POST_LOGIN_REDIRECT=/dashboard
|
||||||
|
FRONTEND_DIST=./web
|
||||||
|
|
||||||
|
# ── Security ──────────────────────────────────────────────────────────────────
|
||||||
|
SESSION_SECRET=change-me-in-production
|
||||||
|
COOKIE_SECURE=false
|
||||||
|
|
||||||
|
# ── Google OAuth (optional) ───────────────────────────────────────────────────
|
||||||
|
GOOGLE_CLIENT_ID=
|
||||||
|
GOOGLE_CLIENT_SECRET=
|
||||||
|
|
||||||
|
# ── Generic OIDC (optional) ───────────────────────────────────────────────────
|
||||||
|
OIDC_ISSUER=
|
||||||
|
OIDC_CLIENT_ID=
|
||||||
|
OIDC_CLIENT_SECRET=
|
||||||
|
|
||||||
|
# ── Misc ──────────────────────────────────────────────────────────────────────
|
||||||
|
# How often buffered click counts are flushed to Postgres (seconds)
|
||||||
|
CLICK_FLUSH_SECONDS=10
|
||||||
@@ -17,13 +17,13 @@ type Cache struct {
|
|||||||
prefix string
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ctx context.Context, addr, password string, db int) (*Cache, error) {
|
func New(ctx context.Context, addr, password string, db int, keyPrefix string) (*Cache, error) {
|
||||||
rdb := redis.NewClient(&redis.Options{Addr: addr, Password: password, DB: db})
|
rdb := redis.NewClient(&redis.Options{Addr: addr, Password: password, DB: db})
|
||||||
if err := rdb.Ping(ctx).Err(); err != nil {
|
if err := rdb.Ping(ctx).Err(); err != nil {
|
||||||
_ = rdb.Close()
|
_ = rdb.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Cache{rdb: rdb, prefix: "code:"}, nil
|
return &Cache{rdb: rdb, prefix: keyPrefix + "code:"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) key(code string) string { return c.prefix + code }
|
func (c *Cache) key(code string) string { return c.prefix + code }
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type Config struct {
|
|||||||
RedisAddr string
|
RedisAddr string
|
||||||
RedisPassword string
|
RedisPassword string
|
||||||
RedisDB int
|
RedisDB int
|
||||||
|
RedisKeyPrefix string
|
||||||
|
|
||||||
// PublicURL is the externally reachable base (used to build OAuth callback
|
// PublicURL is the externally reachable base (used to build OAuth callback
|
||||||
// URLs). PostLoginRedirect is where users land after a successful login.
|
// URLs). PostLoginRedirect is where users land after a successful login.
|
||||||
@@ -76,6 +77,7 @@ func Load() Config {
|
|||||||
RedisAddr: env("REDIS_ADDR", "localhost:6379"),
|
RedisAddr: env("REDIS_ADDR", "localhost:6379"),
|
||||||
RedisPassword: env("REDIS_PASSWORD", ""),
|
RedisPassword: env("REDIS_PASSWORD", ""),
|
||||||
RedisDB: envInt("REDIS_DB", 0),
|
RedisDB: envInt("REDIS_DB", 0),
|
||||||
|
RedisKeyPrefix: env("REDIS_KEY_PREFIX", ""),
|
||||||
PublicURL: env("PUBLIC_URL", "http://localhost:8080"),
|
PublicURL: env("PUBLIC_URL", "http://localhost:8080"),
|
||||||
PostLoginRedirect: env("POST_LOGIN_REDIRECT", "/dashboard"),
|
PostLoginRedirect: env("POST_LOGIN_REDIRECT", "/dashboard"),
|
||||||
FrontendDist: env("FRONTEND_DIST", "./web"),
|
FrontendDist: env("FRONTEND_DIST", "./web"),
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func (c *Container) buildInfra(ctx context.Context) (*infra, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cache, err := rediscache.New(ctx, c.cfg.RedisAddr, c.cfg.RedisPassword, c.cfg.RedisDB)
|
cache, err := rediscache.New(ctx, c.cfg.RedisAddr, c.cfg.RedisPassword, c.cfg.RedisDB, c.cfg.RedisKeyPrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pool.Close()
|
pool.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user