blob: cc556fffbdf4bbb5c5de895bbdbb34d70f7bf352 [file] [log] [blame]
iomodo48c837e2021-02-19 01:17:07 +04001package model
2
3const (
4 databaseDriverPostgres = "postgres"
5 defaultDataSource = "postgres://user:test@localhost/pcloud_test?sslmode=disable&connect_timeout=10"
iomodob892d072021-02-22 00:23:16 +04006
7 defaultHTTPHost = "0.0.0.0"
8 defaultHTTPPort = 9086
9 defaultHTTPReadTimeout = 5
10 defaultHTTPWriteTimeout = 10
11 defaultHTTPIdleTimeout = 120
12
13 defaultGRPCPort = 9087
iomodo48c837e2021-02-19 01:17:07 +040014)
15
16type Config struct {
iomodoc0479a62021-02-22 20:08:36 +040017 SQL SQLConfig
18 HTTP HTTPConfig
19 GRPC GRPCConfig
iomodo352127d2021-03-26 20:10:32 +040020 App AppConfig
iomodo48c837e2021-02-19 01:17:07 +040021}
22
iomodoc6abf5b2021-02-19 14:48:03 +040023func NewConfig() *Config {
24 config := &Config{}
25 config.SetDefaults()
26 return config
27}
28
iomodo48c837e2021-02-19 01:17:07 +040029func (c *Config) SetDefaults() {
iomodoc0479a62021-02-22 20:08:36 +040030 c.SQL.SetDefaults()
31 c.HTTP.SetDefaults()
32 c.GRPC.SetDefaults()
iomodo48c837e2021-02-19 01:17:07 +040033}
34
iomodoc0479a62021-02-22 20:08:36 +040035type SQLConfig struct {
iomodob892d072021-02-22 00:23:16 +040036 DriverName string
37 DataSource string
iomodo48c837e2021-02-19 01:17:07 +040038}
39
iomodoc0479a62021-02-22 20:08:36 +040040func (s *SQLConfig) SetDefaults() {
iomodo48c837e2021-02-19 01:17:07 +040041 if s.DriverName == "" {
42 s.DriverName = databaseDriverPostgres
43 }
iomodo48c837e2021-02-19 01:17:07 +040044 if s.DataSource == "" {
45 s.DataSource = defaultDataSource
46 }
47}
iomodob892d072021-02-22 00:23:16 +040048
iomodoc0479a62021-02-22 20:08:36 +040049type HTTPConfig struct {
iomodob892d072021-02-22 00:23:16 +040050 Host string
51 Port int
52 ReadTimeout int
53 WriteTimeout int
54 IdleTimeout int
55}
56
iomodoc0479a62021-02-22 20:08:36 +040057func (s *HTTPConfig) SetDefaults() {
iomodob892d072021-02-22 00:23:16 +040058 if s.Host == "" {
59 s.Host = defaultHTTPHost
60 }
iomodob892d072021-02-22 00:23:16 +040061 if s.Port == 0 {
62 s.Port = defaultHTTPPort
63 }
iomodob892d072021-02-22 00:23:16 +040064 if s.ReadTimeout == 0 {
65 s.ReadTimeout = defaultHTTPReadTimeout
66 }
iomodob892d072021-02-22 00:23:16 +040067 if s.WriteTimeout == 0 {
68 s.WriteTimeout = defaultHTTPWriteTimeout
69 }
iomodob892d072021-02-22 00:23:16 +040070 if s.IdleTimeout == 0 {
71 s.IdleTimeout = defaultHTTPIdleTimeout
72 }
73}
74
iomodoc0479a62021-02-22 20:08:36 +040075type GRPCConfig struct {
iomodob892d072021-02-22 00:23:16 +040076 Port int
77}
78
iomodoc0479a62021-02-22 20:08:36 +040079func (s *GRPCConfig) SetDefaults() {
iomodob892d072021-02-22 00:23:16 +040080 if s.Port == 0 {
81 s.Port = defaultGRPCPort
82 }
83}
iomodo352127d2021-03-26 20:10:32 +040084
85type AppConfig struct {
86 EnableSignUp *bool
87}
88
89func (s *AppConfig) SetDefaults() {
90 if s.EnableSignUp == nil {
91 s.EnableSignUp = NewBool(true)
92 }
93}
94
95func NewBool(b bool) *bool { return &b }