forked from ribice/gorsk
/
config.go
59 lines (51 loc) · 1.81 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package config
import (
"fmt"
"io/ioutil"
yaml "gopkg.in/yaml.v2"
)
// Load returns Configuration struct
func Load(path string) (*Configuration, error) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("error reading config file, %s", err)
}
var cfg = new(Configuration)
if err := yaml.Unmarshal(bytes, cfg); err != nil {
return nil, fmt.Errorf("unable to decode into struct, %v", err)
}
return cfg, nil
}
// Configuration holds data necessery for configuring application
type Configuration struct {
Server *Server `yaml:"server,omitempty"`
DB *Database `yaml:"database,omitempty"`
JWT *JWT `yaml:"jwt,omitempty"`
App *Application `yaml:"application,omitempty"`
}
// Database holds data necessery for database configuration
type Database struct {
PSN string `yaml:"psn,omitempty"`
LogQueries bool `yaml:"log_queries,omitempty"`
Timeout int `yaml:"timeout_seconds,omitempty"`
}
// Server holds data necessery for server configuration
type Server struct {
Port string `yaml:"port,omitempty"`
Debug bool `yaml:"debug,omitempty"`
ReadTimeout int `yaml:"read_timeout_seconds,omitempty"`
WriteTimeout int `yaml:"write_timeout_seconds,omitempty"`
}
// JWT holds data necessery for JWT configuration
type JWT struct {
Secret string `yaml:"secret,omitempty"`
Duration int `yaml:"duration_minutes,omitempty"`
RefreshDuration int `yaml:"refresh_duration_minutes,omitempty"`
MaxRefresh int `yaml:"max_refresh_minutes,omitempty"`
SigningAlgorithm string `yaml:"signing_algorithm,omitempty"`
}
// Application holds application configuration details
type Application struct {
MinPasswordStr int `yaml:"min_password_strength,omitempty"`
SwaggerUIPath string `yaml:"swagger_ui_path,omitempty"`
}