Skip to content

Commit

Permalink
fix: correct URL unmarshal error
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 committed Jan 23, 2025
1 parent a1800dc commit 516c1fd
Showing 1 changed file with 21 additions and 0 deletions.
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 516c1fd

Please sign in to comment.