| iomodo | 48c837e | 2021-02-19 01:17:07 +0400 | [diff] [blame] | 1 | package model |
| 2 | |
| 3 | const ( |
| 4 | databaseDriverPostgres = "postgres" |
| 5 | defaultDataSource = "postgres://user:test@localhost/pcloud_test?sslmode=disable&connect_timeout=10" |
| 6 | ) |
| 7 | |
| 8 | type Config struct { |
| 9 | SqlSettings SqlSettings |
| 10 | } |
| 11 | |
| iomodo | c6abf5b | 2021-02-19 14:48:03 +0400 | [diff] [blame] | 12 | func NewConfig() *Config { |
| 13 | config := &Config{} |
| 14 | config.SetDefaults() |
| 15 | return config |
| 16 | } |
| 17 | |
| iomodo | 48c837e | 2021-02-19 01:17:07 +0400 | [diff] [blame] | 18 | func (c *Config) SetDefaults() { |
| 19 | c.SqlSettings.SetDefaults() |
| 20 | } |
| 21 | |
| 22 | type SqlSettings struct { |
| 23 | DriverName string `access:"environment,write_restrictable,cloud_restrictable"` |
| 24 | DataSource string `access:"environment,write_restrictable,cloud_restrictable"` |
| 25 | } |
| 26 | |
| 27 | func (s *SqlSettings) SetDefaults() { |
| 28 | if s.DriverName == "" { |
| 29 | s.DriverName = databaseDriverPostgres |
| 30 | } |
| 31 | |
| 32 | if s.DataSource == "" { |
| 33 | s.DataSource = defaultDataSource |
| 34 | } |
| 35 | } |