58 lines
953 B
Go
58 lines
953 B
Go
package host
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
type traefikClient struct {
|
|
client *http.Client
|
|
domain string
|
|
address url.URL
|
|
}
|
|
|
|
func newClient(domain string, addr string) *traefikClient {
|
|
return &traefikClient{
|
|
domain: domain,
|
|
address: url.URL{
|
|
Scheme: "https",
|
|
Host: addr,
|
|
},
|
|
client: &http.Client{
|
|
Transport: &http.Transport{
|
|
TLSClientConfig: &tls.Config{
|
|
ServerName: domain,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c *traefikClient) GetRawData() (*traefikResponse, error) {
|
|
var out traefikResponse
|
|
|
|
url := c.address
|
|
url.Path = "/api/rawdata"
|
|
|
|
req := http.Request{
|
|
Method: "GET",
|
|
URL: &url,
|
|
}
|
|
|
|
req.Host = c.domain
|
|
|
|
r, err := c.client.Do(&req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("make request: %w", err)
|
|
}
|
|
defer r.Body.Close()
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&out); err != nil {
|
|
return nil, fmt.Errorf("unmarshal body: %w", err)
|
|
}
|
|
|
|
return &out, nil
|
|
}
|