forked from tangled.org/core
this repo has no description

appview: config: add redis to config


Signed-off-by: oppiliappan <me@oppi.li>

Changed files
+23
appview
+23
appview/config.go
··· 2 3 import ( 4 "context" 5 6 "github.com/sethvargo/go-envconfig" 7 ) ··· 41 Endpoint string `env:"ENDPOINT, default=https://eu.i.posthog.com"` 42 } 43 44 type Config struct { 45 Core CoreConfig `env:",prefix=TANGLED_"` 46 Jetstream JetstreamConfig `env:",prefix=TANGLED_JETSTREAM_"` ··· 49 Camo CamoConfig `env:",prefix=TANGLED_CAMO_"` 50 Avatar AvatarConfig `env:",prefix=TANGLED_AVATAR_"` 51 OAuth OAuthConfig `env:",prefix=TANGLED_OAUTH_"` 52 } 53 54 func LoadConfig(ctx context.Context) (*Config, error) {
··· 2 3 import ( 4 "context" 5 + "fmt" 6 + "net/url" 7 8 "github.com/sethvargo/go-envconfig" 9 ) ··· 43 Endpoint string `env:"ENDPOINT, default=https://eu.i.posthog.com"` 44 } 45 46 + type RedisConfig struct { 47 + Addr string `env:"ADDR, default=localhost:6379"` 48 + Password string `env:"PASS"` 49 + DB int `env:"DB, default=0"` 50 + } 51 + 52 + func (cfg RedisConfig) ToURL() string { 53 + u := &url.URL{ 54 + Scheme: "redis", 55 + Host: cfg.Addr, 56 + Path: fmt.Sprintf("/%d", cfg.DB), 57 + } 58 + 59 + if cfg.Password != "" { 60 + u.User = url.UserPassword("", cfg.Password) 61 + } 62 + 63 + return u.String() 64 + } 65 + 66 type Config struct { 67 Core CoreConfig `env:",prefix=TANGLED_"` 68 Jetstream JetstreamConfig `env:",prefix=TANGLED_JETSTREAM_"` ··· 71 Camo CamoConfig `env:",prefix=TANGLED_CAMO_"` 72 Avatar AvatarConfig `env:",prefix=TANGLED_AVATAR_"` 73 OAuth OAuthConfig `env:",prefix=TANGLED_OAUTH_"` 74 + Redis RedisConfig `env:",prefix=TANGLED_REDIS_"` 75 } 76 77 func LoadConfig(ctx context.Context) (*Config, error) {