This commit is contained in:
Andrey Belvedersky
2021-06-03 01:59:32 +03:00
parent a4838bb973
commit 18b2d4e554
23 changed files with 821 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
package settings
package config
import (
"errors"
@@ -8,10 +8,10 @@ import (
)
// Load config file from given path
func LoadConfig() (*viper.Viper, error) {
func LoadConfig(file string) (*viper.Viper, error) {
v := viper.New()
v.SetConfigName("./settings")
v.SetConfigName("./" + file)
v.AddConfigPath(".")
v.AutomaticEnv()
if err := v.ReadInConfig(); err != nil {
@@ -27,19 +27,17 @@ func LoadConfig() (*viper.Viper, error) {
// Parse config file
func ParseConfig(v *viper.Viper) (*Config, error) {
var c Config
err := v.Unmarshal(&c)
if err != nil {
log.Printf("unable to decode into struct, %v", err)
return nil, err
}
return &c, nil
}
// Get config
func GetConfig() (*Config, error) {
cfgFile, err := LoadConfig()
cfgFile, err := LoadConfig("settings")
if err != nil {
return nil, err
}
@@ -50,3 +48,17 @@ func GetConfig() (*Config, error) {
}
return cfg, nil
}
func GetReply() (*Reply, error) {
cfgFile, err := LoadConfig("reply")
if err != nil {
return nil, err
}
reply := Reply{}
_err := cfgFile.Unmarshal(&reply)
if _err != nil {
log.Printf("unable to decode into struct, %v", err)
return nil, err
}
return &reply, nil
}

4
pkg/config/reply.go Normal file
View File

@@ -0,0 +1,4 @@
package config
type Reply struct {
}

View File

@@ -1,16 +1,29 @@
package settings
package config
import "github.com/andygrunwald/go-jira"
type Config struct {
Debug bool
Jira JiraConfig
Debug bool
Developers []int
Telegram TelegramConfig
Jira JiraConfig
BotVersion float64
Redis ReidsConfig
}
type TelegramConfig struct {
Token string
Url string
}
type JiraConfig struct {
Url string
Auth AuthConfig
Auth jira.BasicAuthTransport
}
type AuthConfig struct {
Username string
type ReidsConfig struct {
Host string
Port string
Password string
Db int
}