Skip to content

Commit

Permalink
refactor(service): make Info fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Aug 27, 2024
1 parent 65b2578 commit 3f8a177
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewService(cfg config.APIService, server StrictServerInterface) *Service {
SimpleHTTP: service.NewSimpleHTTP("API", endpoints),

Check warning on line 21 in api/service.go

View check run for this annotation

Codecov / codecov/patch

api/service.go#L20-L21

Added lines #L20 - L21 were not covered by tests
}

registerOpenAPIEndpoints(s.Mux, server)
registerOpenAPIEndpoints(s.Router(), server)

Check warning on line 24 in api/service.go

View check run for this annotation

Codecov / codecov/patch

api/service.go#L24

Added line #L24 was not covered by tests

return s

Check warning on line 26 in api/service.go

View check run for this annotation

Codecov / codecov/patch

api/service.go#L26

Added line #L26 was not covered by tests
}
2 changes: 1 addition & 1 deletion metrics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})),
)
Expand Down
2 changes: 1 addition & 1 deletion server/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3f8a177

Please sign in to comment.