owncast/config.go

98 lines
2.4 KiB
Go
Raw Normal View History

2020-06-02 01:53:31 +02:00
package main
import (
"fmt"
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
// Config struct
type Config struct {
IPFS IPFS `yaml:"ipfs"`
PublicHLSPath string `yaml:"publicHLSPath"`
PrivateHLSPath string `yaml:"privateHLSPath"`
VideoSettings VideoSettings `yaml:"videoSettings"`
Files Files `yaml:"files"`
FFMpegPath string `yaml:"ffmpegPath"`
WebServerPort int `yaml:"webServerPort"`
2020-06-03 10:34:05 +02:00
S3 S3 `yaml:"s3"`
2020-06-02 01:53:31 +02:00
}
type VideoSettings struct {
2020-06-09 10:52:15 +02:00
ChunkLengthInSeconds int `yaml:"chunkLengthInSeconds"`
StreamingKey string `yaml:"streamingKey"`
2020-06-09 22:15:44 +02:00
EncoderPreset string `yaml:"encoderPreset"`
2020-06-09 10:52:15 +02:00
StreamQualities []StreamQuality `yaml:"streamQualities"`
}
type StreamQuality struct {
Bitrate string `yaml:"bitrate"`
2020-06-02 01:53:31 +02:00
}
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
type Files struct {
MaxNumberInPlaylist int `yaml:"maxNumberInPlaylist"`
MaxNumberOnDisk int `yaml:"maxNumberOnDisk"`
}
type IPFS struct {
Enabled bool `yaml:"enabled"`
Gateway string `yaml:"gateway"`
}
2020-06-03 10:34:05 +02:00
type S3 struct {
Enabled bool `yaml:"enabled"`
AccessKey string `yaml:"accessKey"`
Secret string `yaml:"secret"`
Bucket string `yaml:"bucket"`
Region string `yaml:"region"`
}
2020-06-02 01:53:31 +02:00
func getConfig() Config {
filePath := "config/config.yaml"
if !fileExists(filePath) {
2020-06-02 02:15:11 +02:00
log.Fatal("ERROR: valid config/config.yaml is required. Copy config/config-example.yaml to config/config.yaml and edit.")
2020-06-02 01:53:31 +02:00
}
yamlFile, err := ioutil.ReadFile(filePath)
var config Config
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
panic(err)
}
2020-06-03 10:34:05 +02:00
// fmt.Printf("%+v\n", config)
2020-06-02 01:53:31 +02:00
return config
}
func checkConfig(config Config) {
2020-06-03 10:34:05 +02:00
if config.S3.Enabled && config.IPFS.Enabled {
panic("S3 and IPFS support cannot be enabled at the same time. Choose one.")
}
2020-06-02 01:53:31 +02:00
if !fileExists(config.PrivateHLSPath) {
panic(fmt.Sprintf("%s does not exist.", config.PrivateHLSPath))
}
if !fileExists(config.PublicHLSPath) {
panic(fmt.Sprintf("%s does not exist.", config.PublicHLSPath))
}
if !fileExists(config.FFMpegPath) {
panic(fmt.Sprintf("ffmpeg does not exist at %s.", config.FFMpegPath))
}
2020-06-09 22:15:44 +02:00
if config.VideoSettings.EncoderPreset == "" {
panic("A video encoder preset is required to be set in the config file.")
}
if len(config.VideoSettings.StreamQualities) < 1 {
panic("At least one stream quality must be set in the config file.")
}
2020-06-02 01:53:31 +02:00
}