-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenerateUserDomainName.go
48 lines (39 loc) · 1.11 KB
/
GenerateUserDomainName.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package platform
import (
"encoding/json"
"fmt"
"github.com/ao-space/platform-sdk-go/utils"
"github.com/jinzhu/copier"
"net/http"
"net/url"
)
type GenerateUserDomainRequest struct {
EffectiveTime int `json:"effectiveTime"`
}
type GenerateUserDomainResponse struct {
BoxUUID string `json:"boxUUID"`
Subdomain string `json:"subdomain"`
ExpiresAt string `json:"expiresAt"`
}
func (c *Client) GenerateUserDomain(input *GenerateUserDomainRequest) (*GenerateUserDomainResponse, error) {
if !c.IsAvailable(uriGenerateUserDomainName, http.MethodPost) {
return nil, fmt.Errorf("the ability is not available: [%v] %v ", http.MethodPost, uriGenerateUserDomainName)
}
path := fmt.Sprintf("platform/boxes/%v/subdomains", c.BoxUUID)
URL := new(url.URL)
copier.Copy(URL, c.BaseURL)
URL = URL.JoinPath(path)
op := new(Operation)
op.SetOperation(http.MethodPost, URL)
requestBody, _ := json.Marshal(input)
resp, err := c.Send(op, requestBody)
if err != nil {
return nil, err
}
output := new(GenerateUserDomainResponse)
err = utils.GetBody(resp, output)
if err != nil {
return nil, err
}
return output, nil
}