Skip to content

Commit

Permalink
fix: correct URL unmarshal error (#3364)
Browse files Browse the repository at this point in the history
This commit addresses an issue where the `URL` field in the `/status` response was not properly unmarshalled as a URL, resulting in a `cannot unmarshal string into Go struct field` error. The fix ensures correct unmarshalling for seamless handling of the response.
  • Loading branch information
rickstaa authored Jan 23, 2025
1 parent a1800dc commit 56ab75e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#### CLI

- [#3364](https://github.com/livepeer/go-livepeer/pull/3364) fix orchestrator status json unmarshalling issue.

#### General

#### Broadcaster
Expand Down
21 changes: 21 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func FromRemoteInfos(infos []*net.OrchestratorInfo) OrchestratorDescriptors {
return ods
}

// MarshalJSON ensures that URL is marshaled as a string.
func (u *OrchestratorLocalInfo) MarshalJSON() ([]byte, error) {
type Alias OrchestratorLocalInfo
return json.Marshal(&struct {
Expand All @@ -97,6 +98,26 @@ func (u *OrchestratorLocalInfo) MarshalJSON() ([]byte, error) {
})
}

// UnmarshalJSON ensures that URL string is unmarshaled as a URL.
func (o *OrchestratorLocalInfo) UnmarshalJSON(data []byte) error {
type Alias OrchestratorLocalInfo
aux := &struct {
URL string `json:"Url"`
*Alias
}{
Alias: (*Alias)(o),
}
if err := json.Unmarshal(data, aux); err != nil {
return err
}
parsedURL, err := url.Parse(aux.URL)
if err != nil {
return err
}
o.URL = parsedURL
return nil
}

type ScorePred = func(float32) bool
type OrchestratorPool interface {
GetInfos() []OrchestratorLocalInfo
Expand Down

0 comments on commit 56ab75e

Please sign in to comment.