Maint: package local narrow Logger interfaces

This commit is contained in:
Quentin McGaw (desktop)
2021-09-23 16:58:21 +00:00
parent d8e008606f
commit cf95692b93
57 changed files with 414 additions and 154 deletions

View File

@@ -7,22 +7,21 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/dns"
"github.com/qdm12/golibs/logging"
)
func newDNSHandler(ctx context.Context, looper dns.Looper,
logger logging.Logger) http.Handler {
warner warner) http.Handler {
return &dnsHandler{
ctx: ctx,
looper: looper,
logger: logger,
warner: warner,
}
}
type dnsHandler struct {
ctx context.Context
looper dns.Looper
logger logging.Logger
warner warner
}
func (h *dnsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -47,7 +46,7 @@ func (h *dnsHandler) getStatus(w http.ResponseWriter) {
encoder := json.NewEncoder(w)
data := statusWrapper{Status: string(status)}
if err := encoder.Encode(data); err != nil {
h.logger.Warn(err.Error())
h.warner.Warn(err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
@@ -72,7 +71,7 @@ func (h *dnsHandler) setStatus(w http.ResponseWriter, r *http.Request) {
}
encoder := json.NewEncoder(w)
if err := encoder.Encode(outcomeWrapper{Outcome: outcome}); err != nil {
h.logger.Warn(err.Error())
h.warner.Warn(err.Error())
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}