forked from asonawalla/gazette
/
service.go
35 lines (29 loc) · 1.28 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
package mainboilerplate
import (
"fmt"
"github.com/LiveRamp/gazette/v2/pkg/allocator"
"github.com/LiveRamp/gazette/v2/pkg/keyspace"
"github.com/LiveRamp/gazette/v2/pkg/protocol"
)
// ZoneConfig configures the zone of the application.
type ZoneConfig struct {
Zone string `long:"zone" env:"ZONE" default:"local" description:"Availability zone within which this process is running"`
}
// ServiceConfig represents identification and addressing configuration of the process.
type ServiceConfig struct {
ZoneConfig
ID string `long:"id" env:"ID" default:"localhost" description:"Unique ID of the process"`
Host string `long:"host" env:"HOST" default:"localhost" description:"Addressable, advertised hostname of this process"`
Port uint16 `long:"port" env:"PORT" default:"8080" description:"Service port for HTTP and gRPC requests"`
}
// ProcessSpec of the ServiceConfig.
func (cfg ServiceConfig) ProcessSpec() protocol.ProcessSpec {
return protocol.ProcessSpec{
Id: protocol.ProcessSpec_ID{Zone: cfg.Zone, Suffix: cfg.ID},
Endpoint: protocol.Endpoint(fmt.Sprintf("http://%s:%d", cfg.Host, cfg.Port)),
}
}
// MemberKey of an allocator implied by the ServiceConfig.
func (cfg ServiceConfig) MemberKey(ks *keyspace.KeySpace) string {
return allocator.MemberKey(ks, cfg.Zone, cfg.ID)
}