-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.go
58 lines (45 loc) · 1.32 KB
/
service.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
package config
import (
"fmt"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"net/http"
)
type ServiceConfig struct {
Name string `yaml:"Name"`
URL string `yaml:"URL"`
ApiKeyEnvironmentVariable string `yaml:"ApiKeyEnvironmentVariable"`
PublicKeyEnvironmentVariable string `yaml:"PublicKeyEnvironmentVariable"`
ComponentConfigOverrides ComponentConfigs
Endpoints EndpointMap
mergedComponentConfigs ComponentConfigs
Client *http.Client `json:"-"`
}
func (s *ServiceConfig) setClient(cc ClientConfig) {
s.Client = httpClient(cc)
}
type Endpoint struct {
Name string
Path string
}
type EndpointMap map[string]*Endpoint
type ServiceConfigMap map[string]*ServiceConfig
func (s *ServiceConfig) mergedComponents() ComponentConfigs {
return s.mergedComponentConfigs
}
func (m *ServiceConfigMap) UnmarshalYAML(value *yaml.Node) error {
if value.Kind != yaml.SequenceNode {
return fmt.Errorf("UnmarshalYAML: expected a sequence, got %v", value.Kind)
}
configs := make(ServiceConfigMap, len(*m))
for _, item := range value.Content {
config := new(ServiceConfig)
if err := item.Decode(&config); err != nil {
log.Errorf("UnmarshalYAML - decode error: %v", err)
return err
}
configs[config.Name] = config
}
*m = configs
return nil
}