Repository: cloudflare/cloudflare-go
Pull request #1190 (2023-01-30 03:55:52)

Change StreamVideo.Duration type from int to float64.
## Description

Calling `StreamListVideos` raises the following exception because StreamVideo.Duration is int but Cloudflare API returns a decimal number:

```
json: cannot unmarshal number 66.67 into Go struct field StreamVideo.result.duration of type int
```

## Has your change been tested?

Yes. All unit tests has passed and calling StreamListVideos on our account has succeeded.

## Types of changes

This is a bug fix and breaks compatibility (a little) because Duration type has been changed.

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1190.txt b/.changelog/1190.txt
new file mode 100644
index 000000000..6e12a08b1
--- /dev/null
+++ b/.changelog/1190.txt
@@ -0,0 +1,7 @@
+```release-note:bug
+stream: Fix a bug that cannot unmarshal video duration number.
+```
+
+```release-note:breaking-change
+stream: StreamVideo.Duration has changed from int to float64.
+```
diff --git a/stream.go b/stream.go
index 95edd6b5e..afca00149 100644
--- a/stream.go
+++ b/stream.go
@@ -28,7 +28,7 @@ var (
 type StreamVideo struct {
 	AllowedOrigins        []string                 `json:"allowedOrigins,omitempty"`
 	Created               *time.Time               `json:"created,omitempty"`
-	Duration              int                      `json:"duration,omitempty"`
+	Duration              float64                  `json:"duration,omitempty"`
 	Input                 StreamVideoInput         `json:"input,omitempty"`
 	MaxDurationSeconds    int                      `json:"maxDurationSeconds,omitempty"`
 	Meta                  map[string]interface{}   `json:"meta,omitempty"`


Test patch:
diff --git a/stream_test.go b/stream_test.go
index eb821cec6..01cc21cb9 100644
--- a/stream_test.go
+++ b/stream_test.go
@@ -22,7 +22,7 @@ const (
       "example.com"
     ],
     "created": "2014-01-02T02:20:00Z",
-    "duration": 300,
+    "duration": 300.5,
     "input": {
       "height": 1080,
       "width": 1920
@@ -86,7 +86,7 @@ func createTestVideo() StreamVideo {
 	return StreamVideo{
 		AllowedOrigins:     []string{"example.com"},
 		Created:            &created,
-		Duration:           300,
+		Duration:           300.5,
 		Input:              StreamVideoInput{Height: 1080, Width: 1920},
 		MaxDurationSeconds: 300,
 		Modified:           &modified,
@@ -285,7 +285,7 @@ func TestStream_ListVideos(t *testing.T) {
       "example.com"
     ],
     "created": "2014-01-02T02:20:00Z",
-    "duration": 300,
+    "duration": 300.5,
     "input": {
       "height": 1080,
       "width": 1920