-
Notifications
You must be signed in to change notification settings - Fork 17
/
service.go
59 lines (45 loc) · 1.64 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
59
package apihub
import (
"time"
"code.cloudfoundry.org/lager"
)
const SERVICES_PREFIX string = "services_"
//go:generate counterfeiter . Service
//go:generate counterfeiter . ServicePublisher
//go:generate counterfeiter . ServiceSubscriber
type Service interface {
// Host returns the subdomain/host used to access a service.
Host() string
// Start adds a service in the service pool to host upcoming requests.
Start() error
// Stop stops proxying the requests.
Stop() error
// Info returns information about a service.
Info() (ServiceSpec, error)
// Backends returns all backends in the service.
Backends() ([]BackendInfo, error)
// Timeout waits for the duration before returning an error to the client.
SetTimeout(time.Duration) error
}
type ServicePublisher interface {
Publish(logger lager.Logger, prefix string, spec ServiceSpec) error
Unpublish(logger lager.Logger, prefix string, host string) error
}
type ServiceSubscriber interface {
Subscribe(logger lager.Logger, prefix string, servicesCh chan ServiceSpec, stop <-chan struct{}) error
}
// ServiceInfo holds information about a service.
type ServiceSpec struct {
// Host specifies the subdomain/host used to access the service.
Host string `json:"host"`
Disabled bool `json:"disabled"`
Timeout time.Duration `json:"timeout"` // in milliseconds
Backends []BackendInfo `json:"backends,omitempty"`
}
// Backend holds information about a backend.
type BackendInfo struct {
Address string `json:"address"`
Disabled bool `json:"disabled"`
HeartBeatAddress string `json:"heart_beat_address"`
HeartBeatTimeout int `json:"heart_beat_timeout"`
}