cloudflare / cloudflare/cloudflare-go
LiveInput.Status field contains JSON string instead of simple string
- Dominant language
- Go
- Stars
- 2.1k
- Forks
- 781
- Avg merge
- 12h 38m
- Merged PRs (30d)
- 4
Description
### Confirm this is a Go library issue and not an underlying Cloudflare API issue
- [x] This is an issue with the Go library
### Describe the bug
The `LiveInput.Status` field is defined as `LiveInputStatus` (a string type) in the SDK, but the actual Cloudflare API returns a **JSON-encoded string** containing a structured object with `current` and `history` fields. This makes it impossible to access the actual status value (e.g., "connected", "disconnected") without manually parsing the JSON string.
**Type definition in SDK (v6.3.0):**
```go
type LiveInput struct {
Status LiveInputStatus `json:"status,nullable"`
// ...
}
type LiveInputStatus string
const LiveInputStatusConnected LiveInputStatus = "connected"
```
https://github.com/cloudflare/cloudflare-go/blob/d124aa26bdcd832dbd4b082db30b94887243437f/stream/liveinput.go#L166
Actual API response when stream is active:
```
{
"status": "{\n \"current\": {\n \"ingestProtocol\": \"rtmp\",\n \"reason\": \"connected\",\n \"state\": \"connected\",\n \"statusEnteredAt\": \"2025-11-24T18:12:11.658Z\",\n \"statusLastSeen\": \"2025-11-24T18:12:56.456Z\"\n },\n \"history\": []\n}"
}
```
When the stream is stop:
```
{
"status": "{\n \"current\": {\n \"ingestProtocol\": \"rtmp\",\n \"reason\": \"client_disconnect\",\n \"state\": \"disconnected\",\n \"statusEnteredAt\": \"2025-11-24T18:14:52.707Z\",\n \"statusLastSeen\": \"2025-11-24T18:14:52.707Z\"\n },\n \"history\": [\n {\n \"ingestProtocol\": \"rtmp\",\n \"reason\": \"connected\",\n \"state\": \"connected\",\n \"statusEnteredAt\": \"2025-11-24T18:12:11.658Z\"\n }\n ]\n }"
}
```
When the stream is idle, status is an empty string `""`.
### To Reproduce
1. Create a Cloudflare Stream Live Input via the API
2. Start streaming to it using OBS or similar tool (RTMPS)
3. Call client.Stream.LiveInputs.Get(ctx, liveInputID, ...) in Go
4. Inspect the live.Status field value
5. Observe that live.Status contains a JSON string, not a simple status value like "connected"
### Code snippets
```Go
### 1. Minimal reproduction code
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/cloudflare/cloudflare-go/v6"
"github.com/cloudflare/cloudflare-go/v6/stream"
)
func main() {
ctx := context.Background()
client, _ := cloudflare.New(cloudflare.WithAPIToken("your-token"))
// Get live input
live, err := client.Stream.LiveInputs.Get(ctx, "live-input-id", stream.LiveInputGetParams{
AccountID: cloudflare.String("account-id"),
})
if err != nil {
panic(err)
}
// Print status type and value
fmt.Printf("Status type: %T\n", live.Status)
fmt.Printf("Status value: %q\n", string(live.Status))
// This doesn't work - Status is not a simple string
if live.Status == stream.LiveInputStatusConnected {
fmt.Println("Connected") // This will never match
}
}
2. Actual output when stream is active
Status type: stream.LiveInputStatus
Status value: "{\n \"current\": {\n \"ingestProtocol\": \"rtmp\",\n \"reason\": \"connected\",\n \"state\": \"connected\",\n
\"statusEnteredAt\": \"2025-11-24T18:12:11.658Z\",\n \"statusLastSeen\": \"2025-11-24T18:12:56.456Z\"\n },\n \"history\": []\n}"
3. Actual output when stream is idle
Status type: stream.LiveInputStatus
Status value: ""
4. Current workaround
// Define the actual structure
type LiveStatusObject struct {
Current struct {
IngestProtocol string `json:"ingestProtocol"`
Reason string `json:"reason"` // This is the actual status
State string `json:"state"`
StatusEnteredAt string `json:"statusEnteredAt"`
StatusLastSeen string `json:"statusLastSeen"`
} `json:"current"`
History []interface{} `json:"history"`
}
// Manual parsing required
var statusObj LiveStatusObject
if live.Status != "" {
if err := json.Unmarshal([]byte(live.Status), &statusObj); err != nil {
return err
}
}
// Now we can check the actual status
if statusObj.Current.Reason == "connected" {
fmt.Println("Connected")
}
```
The Status field should either be:
1. A proper struct type that the SDK unmarshals automatically, or
2. The API should return a simple string instead of a JSON-encoded string
### OS
macOS
### Go version
go1.25.4
### Library version
github.com/cloudflare/cloudflare-go/v6 v6.3.0
Contributor guide
Assessment
This issue has not been assessed yet.