owncast/config.go

113 lines
3 KiB
Go
Raw Normal View History

2020-06-02 02:53:31 +03:00
package main
import (
"fmt"
"io/ioutil"
2020-06-18 02:29:47 +03:00
log "github.com/sirupsen/logrus"
2020-06-02 02:53:31 +03:00
"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"`
S3 S3 `yaml:"s3"`
EnableOfflineImage bool `yaml:"enableOfflineImage"`
2020-06-02 02:53:31 +03:00
}
type VideoSettings struct {
2020-06-09 11:52:15 +03:00
ChunkLengthInSeconds int `yaml:"chunkLengthInSeconds"`
StreamingKey string `yaml:"streamingKey"`
2020-06-09 23:15:44 +03:00
EncoderPreset string `yaml:"encoderPreset"`
2020-06-09 11:52:15 +03:00
StreamQualities []StreamQuality `yaml:"streamQualities"`
EnablePassthrough bool `yaml:"passthrough"`
OfflineImage string `yaml:"offlineImage"`
2020-06-09 11:52:15 +03:00
}
type StreamQuality struct {
2020-06-15 07:17:01 +03:00
Bitrate int `yaml:"bitrate"`
2020-06-02 02:53:31 +03:00
}
// MaxNumberOnDisk must be at least as large as MaxNumberInPlaylist
type Files struct {
MaxNumberInPlaylist int `yaml:"maxNumberInPlaylist"`
}
type IPFS struct {
Enabled bool `yaml:"enabled"`
Gateway string `yaml:"gateway"`
}
2020-06-03 11:34:05 +03:00
type S3 struct {
Enabled bool `yaml:"enabled"`
Endpoint string `yaml:"endpoint"`
2020-06-03 11:34:05 +03:00
AccessKey string `yaml:"accessKey"`
Secret string `yaml:"secret"`
Bucket string `yaml:"bucket"`
Region string `yaml:"region"`
}
2020-06-02 02:53:31 +03:00
func getConfig() Config {
filePath := "config/config.yaml"
if !fileExists(filePath) {
2020-06-02 03:15:11 +03:00
log.Fatal("ERROR: valid config/config.yaml is required. Copy config/config-example.yaml to config/config.yaml and edit.")
2020-06-02 02:53:31 +03:00
}
yamlFile, err := ioutil.ReadFile(filePath)
var config Config
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
2020-06-18 09:01:49 +03:00
log.Panicln(err)
2020-06-02 02:53:31 +03:00
}
2020-06-03 11:34:05 +03:00
// fmt.Printf("%+v\n", config)
2020-06-02 02:53:31 +03:00
return config
}
func checkConfig(config Config) {
2020-06-03 11:34:05 +03:00
if config.S3.Enabled && config.IPFS.Enabled {
2020-06-18 09:01:49 +03:00
log.Panicln("S3 and IPFS support cannot be enabled at the same time. Choose one.")
2020-06-03 11:34:05 +03:00
}
if config.S3.Enabled {
if config.S3.AccessKey == "" || config.S3.Secret == "" {
2020-06-18 09:01:49 +03:00
log.Panicln("S3 support requires an access key and secret.")
}
if config.S3.Region == "" || config.S3.Endpoint == "" {
2020-06-18 09:01:49 +03:00
log.Panicln("S3 support requires a region and endpoint.")
}
if config.S3.Bucket == "" {
2020-06-18 09:01:49 +03:00
log.Panicln("S3 support requires a bucket created for storing public video segments.")
}
}
2020-06-18 09:01:49 +03:00
// if !fileExists(config.PrivateHLSPath) {
// os.MkdirAll(path.Join(config.PrivateHLSPath, strconv.Itoa(0)), 0777)
// }
2020-06-02 02:53:31 +03:00
2020-06-18 09:01:49 +03:00
// if !fileExists(config.PublicHLSPath) {
// os.MkdirAll(path.Join(config.PublicHLSPath, strconv.Itoa(0)), 0777)
// }
2020-06-02 02:53:31 +03:00
if !fileExists(config.FFMpegPath) {
2020-06-18 09:01:49 +03:00
log.Panicln(fmt.Sprintf("ffmpeg does not exist at %s.", config.FFMpegPath))
2020-06-02 02:53:31 +03:00
}
2020-06-09 23:15:44 +03:00
if config.VideoSettings.EncoderPreset == "" {
2020-06-18 09:01:49 +03:00
log.Panicln("A video encoder preset is required to be set in the config file.")
2020-06-09 23:15:44 +03:00
}
2020-06-02 02:53:31 +03:00
}