mirror of
https://github.com/nxshock/promodj.git
synced 2025-07-03 00:03:37 +05:00
Initial commit
This commit is contained in:
commit
01138252ac
16 changed files with 1195 additions and 0 deletions
42
config.go
Normal file
42
config.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/gookit/validate"
|
||||
)
|
||||
|
||||
// Config represents configuration
|
||||
type Config struct {
|
||||
ListenAddr string `default:":80" validate:"required`
|
||||
|
||||
// Mb
|
||||
BufferSize uint `default:"32" validate:"required|min:1`
|
||||
|
||||
// Kb
|
||||
Bitrate uint `default:"32" validate:"required|min:8|max:320"`
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue