-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.go
89 lines (71 loc) · 2.46 KB
/
conf.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"gualogger/handlers"
"github.com/spf13/viper"
)
type Configuration struct {
Opcua OpcConfig `mapstructure:"opcua"`
ExpMap map[string]interface{} `mapstructure:"exporters"`
Exporters Exporters `mapstructure:"exporters"`
}
type OpcConfig struct {
Connection OpcConnection `mapstructure:"connection"`
Subscription Subscription `mapstructure:"subscription"`
}
type Subscription struct {
Nodeids []string `mapstructure:"nodeids"`
Interval int `mapstructure:"sub_interval"`
}
type OpcConnection struct {
Endpoint string `mapstructure:"endpoint"`
Port int `mapstructure:"port"`
Mode string `mapstructure:"mode"`
Policy string `mapstructure:"policy"`
Authentication OpcAuthentication `mapstructure:"authentication"`
Certificate OpcCerts `mapstructure:"certificate"`
Retries int `mapstructure:"retry_count"`
}
type OpcAuthentication struct {
Type string `mapstructure:"type"`
Credentials struct {
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
} `mapstructure:"credentials"`
Certificate struct {
CertificatePath string `mapstructure:"certificate_path"`
PrivateKeyPath string `mapstructure:"private_key_path"`
} `mapstructure:"certificate"`
}
type OpcCerts struct {
AutoCreate bool `mapstructure:"auto_create"`
CertificatePath string `mapstructure:"certificate_path"`
PrivateKeyPath string `mapstructure:"private_key_path"`
}
type Exporters struct {
TimeScaleDB handlers.TimeScaleDB `mapstructure:"timescale-db"`
Websocket handlers.Websocket `mapstructure:"websocket"`
}
func LoadConfig() (*Configuration, error) {
var conf Configuration
v := viper.New()
v.SetConfigName("config")
v.SetConfigType("yaml")
v.AddConfigPath("/etc/gopclogs") // Linux FS
v.AddConfigPath("$HOME/.gopclogs") // Windows FS
v.AddConfigPath("./configs") // Local Testing
if err := v.ReadInConfig(); err != nil {
return &conf, err
}
if err := v.Unmarshal(&conf); err != nil {
return &conf, err
}
return &conf, nil
}
// Returns a map of all possible Exporters
// To add a new Exporter add a new entry in format [`conf key name`]=Exporter struct
func (e *Exporters) GetExporterRegister() map[string]handlers.Exporter {
exp := make(map[string]handlers.Exporter)
exp["timescale-db"] = &e.TimeScaleDB
exp["websocket"] = &e.Websocket
return exp
}