38 lines
707 B
Go
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
|
|
}
|