fossteams-api/pkg/mt/tenant.go
2022-10-13 02:42:58 +02:00

42 lines
899 B
Go

package mt
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type VerifiedDomain struct {
Name string
}
func (m *Service) GetVerifiedDomains() (*[]VerifiedDomain, error) {
endpointUrl := m.getEndpoint("/tenant/verifiedDomains")
req, err := m.AuthenticatedRequest("GET", endpointUrl.String(), nil)
if err != nil {
return nil, err
}
resp, err := m.client.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
bodyString, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("invalid status code %d", resp.StatusCode)
}
return nil, fmt.Errorf("invalid status code %d: resp = %s", resp.StatusCode, string(bodyString))
}
var verifiedDomains []VerifiedDomain
dec := json.NewDecoder(resp.Body)
dec.DisallowUnknownFields()
err = dec.Decode(&verifiedDomains)
if err != nil {
return nil, err
}
return &verifiedDomains, nil
}