From 68971d0c7a69d884f62fed1dba1519484a951e47 Mon Sep 17 00:00:00 2001 From: ThinkChaos Date: Wed, 3 Apr 2024 17:48:12 -0400 Subject: [PATCH] refactor(service): make `Info` fields private --- api/service.go | 2 +- metrics/service.go | 2 +- server/doh.go | 2 +- service/http.go | 6 +++--- service/service.go | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/service.go b/api/service.go index ee86c08bc..61e17fc17 100644 --- a/api/service.go +++ b/api/service.go @@ -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 } diff --git a/metrics/service.go b/metrics/service.go index 32b49e6cf..bb6f356bf 100644 --- a/metrics/service.go +++ b/metrics/service.go @@ -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{})), ) diff --git a/server/doh.go b/server/doh.go index 64354c610..9fd4e1b8b 100644 --- a/server/doh.go +++ b/server/doh.go @@ -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) diff --git a/service/http.go b/service/http.go index a15d823df..a85a7d99b 100644 --- a/service/http.go +++ b/service/http.go @@ -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) diff --git a/service/service.go b/service/service.go index d452c1796..ed35fb23f 100644 --- a/service/service.go +++ b/service/service.go @@ -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.