41 lines
669 B
Go
41 lines
669 B
Go
package config
|
|
|
|
import (
|
|
"gopkg.in/yaml.v3"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var app App
|
|
|
|
type App struct {
|
|
Data string `yaml:"data"`
|
|
Db string `yaml:"db"`
|
|
Static string `yaml:"static"`
|
|
Watermark string `yaml:"watermark"`
|
|
SessionTtl time.Duration `yaml:"session_ttl"`
|
|
AlbumTtl time.Duration `yaml:"album_ttl"`
|
|
}
|
|
|
|
func ReadConfig(filename string) error {
|
|
// read config from yaml file
|
|
file, err := os.Open(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer file.Close()
|
|
|
|
// decode yaml
|
|
decoder := yaml.NewDecoder(file)
|
|
err = decoder.Decode(&app)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Get() App {
|
|
return app
|
|
}
|