MCPcopy
hub / github.com/usefathom/fathom / Parse

Function Parse

pkg/config/config.go:47–82  ·  view source on GitHub ↗

Parse environment into a Config struct

()

Source from the content-addressed store, hash-verified

45
46// Parse environment into a Config struct
47func Parse() *Config {
48 var cfg Config
49
50 // with config file loaded into env values, we can now parse env into our config struct
51 err := envconfig.Process("Fathom", &cfg)
52 if err != nil {
53 log.Fatalf("Error parsing configuration from environment: %s", err)
54 }
55
56 if cfg.Database.URL != "" {
57 u, err := url.Parse(cfg.Database.URL)
58 if err != nil {
59 log.Fatalf("Error parsing DATABASE_URL from environment: %s", err)
60 }
61 if u.Scheme == "postgres" {
62 cfg.Database.Driver = "postgres"
63 }
64 }
65
66 // alias sqlite to sqlite3
67 if cfg.Database.Driver == "sqlite" {
68 cfg.Database.Driver = "sqlite3"
69 }
70
71 // use absolute path to sqlite3 database
72 if cfg.Database.Driver == "sqlite3" {
73 cfg.Database.Name, _ = filepath.Abs(cfg.Database.Name)
74 }
75
76 // if secret key is empty, use a randomly generated one
77 if cfg.Secret == "" {
78 cfg.Secret = randomString(40)
79 }
80
81 return &cfg
82}
83
84func randomString(len int) string {
85 bytes := make([]byte, len)

Callers 3

beforeFunction · 0.92
TestParseFunction · 0.85
TestDatabaseURLFunction · 0.85

Calls 1

randomStringFunction · 0.70

Tested by 2

TestParseFunction · 0.68
TestDatabaseURLFunction · 0.68