chore(all): return concrete types, accept interfaces

- Remove exported interfaces unused locally
- Define interfaces to accept arguments
- Return concrete types, not interfaces
This commit is contained in:
Quentin McGaw
2022-06-11 01:34:30 +00:00
parent 0378fe4a7b
commit 578ef768ab
132 changed files with 594 additions and 935 deletions

View File

@@ -5,22 +5,20 @@ import (
"encoding/json"
"net/http"
"strings"
"github.com/qdm12/gluetun/internal/dns"
)
func newDNSHandler(ctx context.Context, looper dns.Looper,
func newDNSHandler(ctx context.Context, loop DNSLoop,
warner warner) http.Handler {
return &dnsHandler{
ctx: ctx,
looper: looper,
loop: loop,
warner: warner,
}
}
type dnsHandler struct {
ctx context.Context //nolint:containedctx
looper dns.Looper
loop DNSLoop
warner warner
}
@@ -42,7 +40,7 @@ func (h *dnsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
func (h *dnsHandler) getStatus(w http.ResponseWriter) {
status := h.looper.GetStatus()
status := h.loop.GetStatus()
encoder := json.NewEncoder(w)
data := statusWrapper{Status: string(status)}
if err := encoder.Encode(data); err != nil {
@@ -64,7 +62,7 @@ func (h *dnsHandler) setStatus(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
outcome, err := h.looper.ApplyStatus(h.ctx, status)
outcome, err := h.loop.ApplyStatus(h.ctx, status)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return