2021-08-14 09:59:41 +05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
"github.com/creasty/defaults"
|
|
|
|
"github.com/gookit/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents configuration
|
|
|
|
type Config struct {
|
2022-07-02 15:09:59 +05:00
|
|
|
ListenAddr string `default:":80" validate:"required"`
|
2021-08-14 09:59:41 +05:00
|
|
|
|
|
|
|
// Mb
|
2022-07-02 15:09:59 +05:00
|
|
|
BufferSize uint `default:"32" validate:"required|min:1"`
|
2021-08-14 09:59:41 +05:00
|
|
|
|
|
|
|
// Kb
|
2023-06-18 14:54:35 +05:00
|
|
|
Bitrate uint64 `default:"32" validate:"required|min:8|max:320"`
|
2021-08-14 09:59:41 +05:00
|
|
|
|
|
|
|
Codec string `default:"libopus" validate:"required"`
|
|
|
|
Format string `default:"opus" validate:"required" `
|
|
|
|
ContentType string `default:"audio/ogg" validate:"required" `
|
|
|
|
}
|
|
|
|
|
|
|
|
var config *Config
|
|
|
|
|
|
|
|
func initConfig(filePath string) error {
|
|
|
|
if _, err := toml.DecodeFile(filePath, &config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := defaults.Set(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if v := validate.Struct(config); !v.Validate() {
|
|
|
|
return errors.New(v.Errors.One())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|