Initial public release of birdwatch-relay
This commit is contained in:
commit
c176f2ad24
17 changed files with 2025 additions and 0 deletions
47
internal/config/config.go
Normal file
47
internal/config/config.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
DBPath string
|
||||
FirebaseKeyPath string
|
||||
PairingCode string
|
||||
FrigateURL string
|
||||
FrigateUser string
|
||||
FrigatePassword string
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
c := &Config{
|
||||
Port: getenv("RELAY_PORT", "8080"),
|
||||
DBPath: getenv("RELAY_DB_PATH", "/data/relay.db"),
|
||||
FirebaseKeyPath: os.Getenv("RELAY_FIREBASE_KEY_PATH"),
|
||||
PairingCode: os.Getenv("RELAY_PAIRING_CODE"),
|
||||
FrigateURL: os.Getenv("FRIGATE_URL"),
|
||||
FrigateUser: os.Getenv("FRIGATE_USER"),
|
||||
FrigatePassword: os.Getenv("FRIGATE_PASSWORD"),
|
||||
}
|
||||
if c.FirebaseKeyPath == "" {
|
||||
return nil, errors.New("RELAY_FIREBASE_KEY_PATH is required")
|
||||
}
|
||||
if c.PairingCode == "" || len(c.PairingCode) < 6 {
|
||||
return nil, errors.New("RELAY_PAIRING_CODE must be at least 6 chars (use: openssl rand -hex 3)")
|
||||
}
|
||||
if c.FrigateURL == "" {
|
||||
return nil, errors.New("FRIGATE_URL is required (e.g. http://localhost:5000)")
|
||||
}
|
||||
// FRIGATE_USER + FRIGATE_PASSWORD optional — empty means Frigate has auth disabled.
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func getenv(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue