create CustomHTML struct and rename PreviewURL struct
MODIFY
waiting_room.go
waiting_room.go
@@ -58,11 +58,16 @@ type WaitingRoomEvent struct {
ShuffleAtEventStart bool `json:"shuffle_at_event_start"`
}
-// WaitingRoomPagePreview describes a WaitingRoomPagePreview object.
-type WaitingRoomPagePreview struct {
+// WaitingRoomPagePreviewURL describes a WaitingRoomPagePreviewURL object.
+type WaitingRoomPagePreviewURL struct {
PreviewURL string `json:"preview_url"`
}
+// WaitingRoomPagePreviewCustomHTML describes a WaitingRoomPagePreviewCustomHTML object.
+type WaitingRoomPagePreviewCustomHTML struct {
+ CustomHTML string `json:"custom_html"`
+}
+
// WaitingRoomDetailResponse is the API response, containing a single WaitingRoom.
type WaitingRoomDetailResponse struct {
Response
@@ -84,7 +89,7 @@ type WaitingRoomStatusResponse struct {
// WaitingRoomPagePreviewResponse is the API response, containing the URL to a custom waiting room preview.
type WaitingRoomPagePreviewResponse struct {
Response
- Result WaitingRoomPagePreview `json:"result"`
+ Result WaitingRoomPagePreviewURL `json:"result"`
}
// WaitingRoomEventDetailResponse is the API response, containing a single WaitingRoomEvent.
@@ -224,21 +229,17 @@ func (api *API) WaitingRoomStatus(ctx context.Context, zoneID, waitingRoomID str
// returns a preview URL.
//
// API reference: https://api.cloudflare.com/#waiting-room-create-a-custom-waiting-room-page-preview
-func (api *API) WaitingRoomPagePreview(ctx context.Context, zoneID, customHTML string) (WaitingRoomPagePreview, error) {
+func (api *API) WaitingRoomPagePreview(ctx context.Context, zoneID, customHTML string) (WaitingRoomPagePreviewURL, error) {
uri := fmt.Sprintf("/zones/%s/waiting_rooms/preview", zoneID)
- res, err := api.makeRequestContext(ctx, http.MethodPost, uri, struct {
- CustomHTML string `json:"custom_html"`
- }{
- CustomHTML: customHTML,
- })
+ res, err := api.makeRequestContext(ctx, http.MethodPost, uri, WaitingRoomPagePreviewCustomHTML{CustomHTML: customHTML})
if err != nil {
- return WaitingRoomPagePreview{}, err
+ return WaitingRoomPagePreviewURL{}, err
}
var r WaitingRoomPagePreviewResponse
err = json.Unmarshal(res, &r)
if err != nil {
- return WaitingRoomPagePreview{}, errors.Wrap(err, errUnmarshalError)
+ return WaitingRoomPagePreviewURL{}, errors.Wrap(err, errUnmarshalError)
}
return r.Result, nil
}

MODIFY
waiting_room_test.go
waiting_room_test.go
@@ -124,7 +124,7 @@ var waitingRoomStatus = WaitingRoomStatus{
MaxEstimatedTimeMinutes: 5,
}
-var waitingRoomPagePreview = WaitingRoomPagePreview{
+var waitingRoomPagePreview = WaitingRoomPagePreviewURL{
PreviewURL: "http://waitingrooms.dev/preview/35af8c12-6d68-4608-babb-b53435a5ddfb",
}

create CustomHTML struct and rename PreviewURL struct