template
This commit is contained in:
@@ -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
4
pkg/config/reply.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package config
|
||||
|
||||
type Reply struct {
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user