-
Notifications
You must be signed in to change notification settings - Fork 61
/
config.go
51 lines (41 loc) · 1.14 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
package config
import (
"sync"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch08/02_advantages/logging"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch08/02_advantages/stats"
)
// LoadFromFile loads the config from the supplied path
func LoadFromFile(path string) (*Config, error) {
// TODO: implement
return &Config{}, nil
}
// Config is the result of loading config from a file
type Config struct {
// Log config
LogLevel int `json:"log_level"`
logger *logging.Logger
loggerInitOnce sync.Once
// Instrumentation config
StatsDHostAndPort string `json:"stats_d_host_and_port"`
stats *stats.Collector
statsInitOnce sync.Once
// Rate Limiter config
RateLimiterMaxConcurrent int `json:"rate_limiter_max_concurrent"`
}
func (c *Config) Logger() *logging.Logger {
c.loggerInitOnce.Do(func() {
// use log level to create new logger
c.logger = &logging.Logger{
Level: c.LogLevel,
}
})
return c.logger
}
func (c *Config) Stats() *stats.Collector {
c.statsInitOnce.Do(func() {
c.stats = &stats.Collector{
HostAndPort: c.StatsDHostAndPort,
}
})
return c.stats
}