feat: initial release
This commit is contained in:
parent
a3cf21f5bd
commit
761174d035
41 changed files with 2008 additions and 217 deletions
58
internal/roles/host/http.go
Normal file
58
internal/roles/host/http.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue