2022-07-08 16:10:46 +00:00
|
|
|
package config
|
|
|
|
|
2022-11-24 13:03:08 +00:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
// BasicService is used as a simple base for node services like Pprof, RPC or
|
|
|
|
// Prometheus monitoring.
|
2022-07-08 16:10:46 +00:00
|
|
|
type BasicService struct {
|
2022-11-25 10:20:53 +00:00
|
|
|
Enabled bool `yaml:"Enabled"`
|
|
|
|
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
|
|
|
Address *string `yaml:"Address,omitempty"`
|
|
|
|
// Deprecated: please, use Addresses section instead. This field will be removed later.
|
2022-12-07 18:16:12 +00:00
|
|
|
Port *string `yaml:"Port,omitempty"`
|
2022-11-25 10:20:53 +00:00
|
|
|
// Addresses holds the list of bind addresses in the form of "address:port".
|
|
|
|
Addresses []string `yaml:"Addresses"`
|
2022-11-24 13:03:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 10:20:53 +00:00
|
|
|
// GetAddresses returns the set of unique (in terms of raw strings) pairs host:port
|
|
|
|
// for the given basic service.
|
|
|
|
func (s BasicService) GetAddresses() []string {
|
|
|
|
addrs := make([]string, len(s.Addresses), len(s.Addresses)+1)
|
|
|
|
copy(addrs, s.Addresses)
|
|
|
|
if s.Address != nil || s.Port != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
|
|
var (
|
|
|
|
addr string
|
2022-12-07 18:16:12 +00:00
|
|
|
port string
|
2022-11-25 10:20:53 +00:00
|
|
|
)
|
|
|
|
if s.Address != nil { //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
|
|
addr = *s.Address //nolint:staticcheck // SA1019: s.Address is deprecated
|
|
|
|
}
|
|
|
|
if s.Port != nil { //nolint:staticcheck // SA1019: s.Port is deprecated
|
|
|
|
port = *s.Port //nolint:staticcheck // SA1019: s.Port is deprecated
|
|
|
|
}
|
2022-12-07 18:16:12 +00:00
|
|
|
addrs = append(addrs, net.JoinHostPort(addr, port))
|
2022-11-25 10:20:53 +00:00
|
|
|
}
|
|
|
|
return addrs
|
2022-07-08 16:10:46 +00:00
|
|
|
}
|