2018-05-17 18:35:53 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
|
2018-06-04 16:48:04 +03:00
|
|
|
"github.com/op/go-logging"
|
|
|
|
"gopkg.in/yaml.v2"
|
2018-05-17 18:35:53 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// TransportConfig struct
|
|
|
|
type TransportConfig struct {
|
2018-06-07 15:35:27 +03:00
|
|
|
LogLevel logging.Level `yaml:"log_level"`
|
|
|
|
Database DatabaseConfig `yaml:"database"`
|
|
|
|
SentryDSN string `yaml:"sentry_dsn"`
|
|
|
|
HTTPServer HTTPServerConfig `yaml:"http_server"`
|
|
|
|
Debug bool `yaml:"debug"`
|
|
|
|
UpdateInterval int `yaml:"update_interval"`
|
|
|
|
ConfigAWS ConfigAWS `yaml:"config_aws"`
|
2018-06-04 16:48:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigAWS struct
|
|
|
|
type ConfigAWS struct {
|
|
|
|
AccessKeyID string `yaml:"access_key_id"`
|
|
|
|
SecretAccessKey string `yaml:"secret_access_key"`
|
|
|
|
Region string `yaml:"region"`
|
|
|
|
Bucket string `yaml:"bucket"`
|
|
|
|
ContentType string `yaml:"content_type"`
|
2018-05-17 18:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|