git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/bunny/hostnames.go (about) 1 package bunny 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 ) 8 9 type AddCustomHostnameInput struct { 10 Hostname string `json:"Hostname"` 11 } 12 13 type RemoveCustomHostnameInput struct { 14 Hostname string `json:"Hostname"` 15 } 16 17 func (client *Client) AddCustomHostname(ctx context.Context, pullZone, hostname string) (err error) { 18 err = client.request(ctx, requestParams{ 19 Payload: AddCustomHostnameInput{ 20 Hostname: hostname, 21 }, 22 Method: http.MethodPost, 23 URL: fmt.Sprintf("%s/pullzone/%s/addHostname", client.apiBaseURL, pullZone), 24 }, nil) 25 26 return 27 } 28 29 func (client *Client) RemoveCustomHostname(ctx context.Context, pullZone, hostname string) (err error) { 30 err = client.request(ctx, requestParams{ 31 Payload: RemoveCustomHostnameInput{ 32 Hostname: hostname, 33 }, 34 Method: http.MethodDelete, 35 URL: fmt.Sprintf("%s/pullzone/%s/removeHostname", client.apiBaseURL, pullZone), 36 }, nil) 37 38 return 39 } 40 41 func (client *Client) LoadFreeCertificate(ctx context.Context, hostname string) (err error) { 42 err = client.request(ctx, requestParams{ 43 Method: http.MethodGet, 44 URL: fmt.Sprintf("%s/pullzone/loadFreeCertificate?hostname=%s", client.apiBaseURL, hostname), 45 }, nil) 46 47 return 48 }