first commit
This commit is contained in:
37
config.go
Normal file
37
config.go
Normal file
@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user