craft-bot/config.go
Timofey.Kovalev 7fdb46d208 first commit
2021-06-10 21:12:47 +03:00

38 lines
707 B
Go

package main
import (
"encoding/json"
"os"
"github.com/pkg/errors"
)
type Config struct {
BotToken string `json:"bot-token"`
ChatID int64 `json:"chat-id"`
Postgres struct {
Host string `json:"host"`
Port uint32 `json:"port"`
User string `json:"user"`
Password string `json:"password"`
DBName string `json:"database"`
} `json:"postgres"`
Http string `json:"http"`
}
func readConfig(fileName string, c *Config) error {
file, err := os.Open(fileName)
if err != nil {
return errors.Wrapf(err, "Failed to open file [%s]", fileName)
}
err = json.NewDecoder(file).Decode(c)
if err != nil {
return errors.Wrap(err, "Failed to parse json config")
}
return nil
}