forked from
tangled.org/core
fork
Configure Feed
Select the types of activity you want to include in your feed.
this repo has no description
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package config
2
3import (
4 "context"
5 "fmt"
6 "net/url"
7
8 "github.com/sethvargo/go-envconfig"
9)
10
11type CoreConfig struct {
12 CookieSecret string `env:"COOKIE_SECRET, default=00000000000000000000000000000000"`
13 DbPath string `env:"DB_PATH, default=appview.db"`
14 ListenAddr string `env:"LISTEN_ADDR, default=0.0.0.0:3000"`
15 AppviewHost string `env:"APPVIEW_HOST, default=https://tangled.sh"`
16 Dev bool `env:"DEV, default=false"`
17}
18
19type OAuthConfig struct {
20 Jwks string `env:"JWKS"`
21}
22
23type JetstreamConfig struct {
24 Endpoint string `env:"ENDPOINT, default=wss://jetstream1.us-east.bsky.network/subscribe"`
25}
26
27type ResendConfig struct {
28 ApiKey string `env:"API_KEY"`
29}
30
31type CamoConfig struct {
32 Host string `env:"HOST, default=https://camo.tangled.sh"`
33 SharedSecret string `env:"SHARED_SECRET"`
34}
35
36type AvatarConfig struct {
37 Host string `env:"HOST, default=https://avatar.tangled.sh"`
38 SharedSecret string `env:"SHARED_SECRET"`
39}
40
41type PosthogConfig struct {
42 ApiKey string `env:"API_KEY"`
43 Endpoint string `env:"ENDPOINT, default=https://eu.i.posthog.com"`
44}
45
46type RedisConfig struct {
47 Addr string `env:"ADDR, default=localhost:6379"`
48 Password string `env:"PASS"`
49 DB int `env:"DB, default=0"`
50}
51
52func (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
66type Config struct {
67 Core CoreConfig `env:",prefix=TANGLED_"`
68 Jetstream JetstreamConfig `env:",prefix=TANGLED_JETSTREAM_"`
69 Resend ResendConfig `env:",prefix=TANGLED_RESEND_"`
70 Posthog PosthogConfig `env:",prefix=TANGLED_POSTHOG_"`
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
77func LoadConfig(ctx context.Context) (*Config, error) {
78 var cfg Config
79 err := envconfig.Process(ctx, &cfg)
80 if err != nil {
81 return nil, err
82 }
83
84 return &cfg, nil
85}