Files
tele-recv/config/loader.go
T

54 lines
1.0 KiB
Go
Raw Normal View History

package config
import (
"github.com/spf13/viper"
)
// Load reads configuration from telegram.yaml using viper.
func Load(path string) (*Config, error) {
v := viper.New()
if path != "" {
v.SetConfigFile(path)
} else {
v.AddConfigPath(".")
v.SetConfigName("telegram")
}
v.AutomaticEnv()
if err := v.ReadInConfig(); err != nil {
return nil, err
}
cfg := &Config{
Serial: SerialConfig{
Device: v.GetString("serial.device"),
Baudrate: v.GetInt("serial.baudrate"),
LogRaw: v.GetBool("serial.lograw"),
},
Telegram: TelegramConfig{
TCP: v.GetBool("telegram.tcp"),
Pulsar: v.GetBool("telegram.pulsar"),
},
SQLite: SQLiteConfig{
File: v.GetString("sqlite.file"),
Init: v.GetBool("sqlite.init"),
},
Socket: SocketConfig{
Address: v.GetString("socket.address"),
},
Pulsar: PulsarConfig{
URL: v.GetString("pulsar.url"),
Topic: v.GetString("pulsar.topic"),
Name: v.GetString("pulsar.name"),
},
Log: LogConfig{
Dir: "./logs",
MaxAge: 60,
RotateHour: 1,
},
}
return cfg, nil
}