-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
36 lines (31 loc) · 890 Bytes
/
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
package main
import (
"gopkg.in/yaml.v3"
"os"
)
type Config struct {
RequestCountMetricName string `yaml:"request_count_metrics_name"`
TargetProcessingTimeMetricName string `yaml:"target_processing_time_metrics_name"`
PathTransformingRules []PathTransformingRule `yaml:"path_transforming_rules"`
TargetPaths []string `yaml:"target_paths"`
CustomTags []Tag `yaml:"custom_tags"`
}
type Tag struct {
Name string `yaml:"name"`
EnvKey string `yaml:"env_key"`
}
func (t *Tag) Key() string {
return os.Getenv(t.EnvKey)
}
func NewConfigFromFile(path string) (*Config, error) {
var config Config
buf, err := os.ReadFile(path)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(buf, &config)
if err != nil {
return nil, err
}
return &config, nil
}