1
0
mirror of synced 2024-11-22 12:26:02 +03:00
mg-transport-telegram/config.go
Alex Lushpai acb2a62da5
Initial release (#1)
Routes
Migrations
Settings form
Activation/deactivation through retailCRM/MG Transport API
2018-05-17 18:35:53 +03:00

56 lines
1.2 KiB
Go

package main
import (
"io/ioutil"
"path/filepath"
logging "github.com/op/go-logging"
yaml "gopkg.in/yaml.v2"
)
// TransportConfig struct
type TransportConfig struct {
LogLevel logging.Level `yaml:"log_level"`
Database DatabaseConfig `yaml:"database"`
SentryDSN string `yaml:"sentry_dsn"`
HTTPServer HTTPServerConfig `yaml:"http_server"`
}
// DatabaseConfig struct
type DatabaseConfig struct {
Connection string `yaml:"connection"`
Logging bool `yaml:"logging"`
TablePrefix string `yaml:"table_prefix"`
MaxOpenConnections int `yaml:"max_open_connections"`
MaxIdleConnections int `yaml:"max_idle_connections"`
ConnectionLifetime int `yaml:"connection_lifetime"`
}
// HTTPServerConfig struct
type HTTPServerConfig struct {
Host string `yaml:"host"`
Listen string `yaml:"listen"`
}
// LoadConfig read configuration file
func LoadConfig(path string) *TransportConfig {
var err error
path, err = filepath.Abs(path)
if err != nil {
panic(err)
}
source, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
var config TransportConfig
if err = yaml.Unmarshal(source, &config); err != nil {
panic(err)
}
return &config
}