/
structs.go
74 lines (65 loc) · 2.37 KB
/
structs.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
package healthcheck
// ApplicationHealthDetailed used to check all application integrations and return status of each of then
type ApplicationHealthDetailed struct {
Name string `json:"name,omitempty"`
Status bool `json:"status"`
Version string `json:"version,omitempty"`
Date string `json:"date"`
Duration float64 `json:"duration"`
Integrations []Integration `json:"integrations"`
}
// ApplicationHealthSimple used to simple return a string 'OK'
type ApplicationHealthSimple struct {
Status string `json:"status"`
}
// Integration is the type result for requests
type Integration struct {
Name string `json:"name"`
Kind string `json:"kind"`
Status bool `json:"status"`
ResponseTime float64 `json:"response_time"` //in seconds
URL string `json:"url"`
Error string `json:"error,omitempty"` // error.Error()
}
// Auth is a default struct to map user/pass protocol
type Auth struct {
User string
Password string
}
// ApplicationConfig is a config contract to init health caller
type ApplicationConfig struct {
Name string `json:"name"`
Version string `json:"version"`
Integrations []IntegrationConfig `json:"integrations"`
}
// IntegrationConfig used to inform each integration config
type IntegrationConfig struct {
Type string `json:"Type"` // must be web | redis | memcache
Name string `json:"name"`
Host string `json:"host"` // yes you can concat host:port here
Port string `json:"port,omitempty"`
Headers []HTTPHeader `json:"headers,omitempty"`
DB int `json:"db,omitempty"` // default value is 0
TimeOut int `json:"timeout,omitempty"` // default value: 10
Auth Auth `json:"auth,omitempty"`
Handle func() error // custom func validtion
}
// HTTPHeader used to setup webservices integrations
type HTTPHeader struct {
Key string `json:"key,omitempty"`
Value string `json:"Value,omitempty"`
}
// Mapped types for IntegrationConfig
const (
Redis = "redis"
Memcached = "memcached"
Web = "web"
Custom = "custom"
)
// Mapped typs for kinds of integrations
const (
RedisIntegration = "Redis DB"
MemcachedIntegration = "Memcached DB"
WebServiceIntegration = "Web service API"
CustomizedTestFunction = "Customized test function"
)