websvc: add tests; imp names

This commit is contained in:
Ainar Garipov
2022-08-31 19:11:00 +03:00
parent dbdae5b4fc
commit b018e150e7
8 changed files with 58 additions and 36 deletions

View File

@@ -2,7 +2,6 @@ package websvc
import (
"net/http"
"net/netip"
"github.com/AdguardTeam/golibs/timeutil"
)
@@ -16,28 +15,8 @@ import (
type RespGetV1SettingsAll struct {
// TODO(a.garipov): Add more as we go.
DNS *respGetV1SettingsAllDNS `json:"dns"`
HTTP *respGetV1SettingsAllHTTP `json:"http"`
}
// respGetV1SettingsAllDNS describes the DNS part of the response of the GET
// /api/v1/settings/all HTTP API.
type respGetV1SettingsAllDNS struct {
// TODO(a.garipov): Add more as we go.
Addresses []netip.AddrPort `json:"addresses"`
BootstrapServers []string `json:"bootstrap_servers"`
UpstreamServers []string `json:"upstream_servers"`
UpstreamTimeout timeutil.Duration `json:"upstream_timeout"`
}
// respGetV1SettingsAllHTTP describes the HTTP part of the response of the GET
// /api/v1/settings/all HTTP API.
type respGetV1SettingsAllHTTP struct {
// TODO(a.garipov): Add more as we go.
Addresses []netip.AddrPort `json:"addresses"`
SecureAddresses []netip.AddrPort `json:"secure_addresses"`
DNS *httpAPIDNSSettings `json:"dns"`
HTTP *httpAPIHTTPSettings `json:"http"`
}
// handleGetSettingsAll is the handler for the GET /api/v1/settings/all HTTP
@@ -49,13 +28,13 @@ func (svc *Service) handleGetSettingsAll(w http.ResponseWriter, r *http.Request)
httpConf := svc.Config()
writeJSONResponse(w, r, &RespGetV1SettingsAll{
DNS: &respGetV1SettingsAllDNS{
DNS: &httpAPIDNSSettings{
Addresses: dnsConf.Addresses,
BootstrapServers: dnsConf.BootstrapServers,
UpstreamServers: dnsConf.UpstreamServers,
UpstreamTimeout: timeutil.Duration{Duration: dnsConf.UpstreamTimeout},
},
HTTP: &respGetV1SettingsAllHTTP{
HTTP: &httpAPIHTTPSettings{
Addresses: httpConf.Addresses,
SecureAddresses: httpConf.SecureAddresses,
},