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:
@@ -17,13 +17,13 @@ type Cache struct {
|
||||
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})
|
||||
if err := rdb.Ping(ctx).Err(); err != nil {
|
||||
_ = rdb.Close()
|
||||
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 }
|
||||
|
||||
@@ -12,9 +12,10 @@ type Config struct {
|
||||
Store string
|
||||
DatabaseURL string
|
||||
|
||||
RedisAddr string
|
||||
RedisPassword string
|
||||
RedisDB int
|
||||
RedisAddr string
|
||||
RedisPassword string
|
||||
RedisDB int
|
||||
RedisKeyPrefix string
|
||||
|
||||
// PublicURL is the externally reachable base (used to build OAuth callback
|
||||
// URLs). PostLoginRedirect is where users land after a successful login.
|
||||
@@ -76,6 +77,7 @@ func Load() Config {
|
||||
RedisAddr: env("REDIS_ADDR", "localhost:6379"),
|
||||
RedisPassword: env("REDIS_PASSWORD", ""),
|
||||
RedisDB: envInt("REDIS_DB", 0),
|
||||
RedisKeyPrefix: env("REDIS_KEY_PREFIX", ""),
|
||||
PublicURL: env("PUBLIC_URL", "http://localhost:8080"),
|
||||
PostLoginRedirect: env("POST_LOGIN_REDIRECT", "/dashboard"),
|
||||
FrontendDist: env("FRONTEND_DIST", "./web"),
|
||||
|
||||
@@ -56,7 +56,7 @@ func (c *Container) buildInfra(ctx context.Context) (*infra, error) {
|
||||
if err != nil {
|
||||
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 {
|
||||
pool.Close()
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user