refactor(service): make `Info` fields private

This commit is contained in:
ThinkChaos 2024-04-03 17:48:12 -04:00
parent 48cad3b786
commit 74b8931998
No known key found for this signature in database
5 changed files with 12 additions and 12 deletions

View File

@ -21,7 +21,7 @@ func NewService(cfg config.APIService, server StrictServerInterface) *Service {
SimpleHTTP: service.NewSimpleHTTP("API", endpoints),
}
registerOpenAPIEndpoints(s.Mux, server)
registerOpenAPIEndpoints(s.Router(), server)
return s
}

View File

@ -27,7 +27,7 @@ func NewService(cfg config.MetricsService, metricsCfg config.Metrics) *Service {
SimpleHTTP: service.NewSimpleHTTP("Metrics", endpoints),
}
s.Mux.Handle(
s.Router().Handle(
metricsCfg.Path,
promhttp.InstrumentMetricHandler(reg, promhttp.HandlerFor(reg, promhttp.HandlerOpts{})),
)

View File

@ -30,7 +30,7 @@ func newDoHService(cfg config.DoHService, handler dnsHandler) *dohService {
handler: handler,
}
s.Mux.Route("/dns-query", func(mux chi.Router) {
s.Router().Route("/dns-query", func(mux chi.Router) {
// Handlers for / also handle /dns-query without trailing slash
mux.Get("/", s.handleGET)

View File

@ -27,18 +27,18 @@ type HTTPService interface {
type HTTPInfo struct {
Info
Mux *chi.Mux
mux *chi.Mux
}
func NewHTTPInfo(name string, endpoints []Endpoint) HTTPInfo {
return HTTPInfo{
Info: NewInfo(name, endpoints),
Mux: chi.NewMux(),
mux: chi.NewMux(),
}
}
func (i *HTTPInfo) Router() chi.Router { return i.Mux }
func (i *HTTPInfo) Router() chi.Router { return i.mux }
var _ HTTPService = (*SimpleHTTP)(nil)

View File

@ -45,19 +45,19 @@ func svcString(s Service) string {
// Info can be embedded in structs to help implement Service.
type Info struct {
Name string
Endpoints []Endpoint
name string
endpoints []Endpoint
}
func NewInfo(name string, endpoints []Endpoint) Info {
return Info{
Name: name,
Endpoints: endpoints,
name: name,
endpoints: endpoints,
}
}
func (i *Info) ServiceName() string { return i.Name }
func (i *Info) ExposeOn() []Endpoint { return i.Endpoints }
func (i *Info) ServiceName() string { return i.name }
func (i *Info) ExposeOn() []Endpoint { return i.endpoints }
func (i *Info) String() string { return svcString(i) }
// GroupByListener returns a map of listener and services grouped by configured address.