Helper tool for stitching together livestream VOD segments and uploading them to YouTube!
at main 64 lines 1.6 kB view raw
1package config 2 3import ( 4 "fmt" 5 "os" 6 7 "github.com/pelletier/go-toml/v2" 8 "golang.org/x/oauth2" 9) 10 11type ( 12 GoogleConfig struct { 13 ApiKey string `toml:"api_key"` 14 ClientID string `toml:"client_id"` 15 ClientSecret string `toml:"client_secret"` 16 } 17 18 Config struct { 19 Host string `toml:"host" comment:"Address to host OAuth2 redirect flow"` 20 RedirectUri string `toml:"redirect_uri" comment:"URI to use in Google OAuth2 flow"` 21 Google GoogleConfig `toml:"google"` 22 Token *oauth2.Token `toml:"token" comment:"This section is filled in automatically on a successful authentication flow."` 23 } 24) 25 26var defaultConfig = Config{ 27 Host: "localhost:8090", 28 RedirectUri: "http://localhost:8090", 29 Google: GoogleConfig{ 30 ApiKey: "<your API key here>", 31 ClientID: "<your client ID here>", 32 ClientSecret: "<your client secret here>", 33 }, 34} 35 36var CONFIG_FILENAME string = "config.toml" 37 38func ReadConfig(filename string) (*Config, error) { 39 cfgBytes, err := os.ReadFile(filename) 40 if err != nil { 41 if os.IsNotExist(err) { 42 return nil, nil 43 } 44 return nil, fmt.Errorf("failed to open file: %v", err) 45 } 46 47 var config Config 48 err = toml.Unmarshal(cfgBytes, &config) 49 if err != nil { return &config, fmt.Errorf("failed to parse: %v", err) } 50 51 return &config, nil 52} 53 54func WriteConfig(cfg *Config, filename string) error { 55 file, err := os.OpenFile(filename, os.O_CREATE | os.O_RDWR, 0644) 56 if err != nil { return err } 57 58 err = toml.NewEncoder(file).Encode(cfg) 59 return err 60} 61 62func GenerateConfig(filename string) error { 63 return WriteConfig(&defaultConfig, filename) 64}