Skip to content

Commit 516c1fd

Browse files
committed
fix: correct URL unmarshal error
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.
1 parent a1800dc commit 516c1fd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

common/types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func FromRemoteInfos(infos []*net.OrchestratorInfo) OrchestratorDescriptors {
8686
return ods
8787
}
8888

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

101+
// UnmarshalJSON ensures that URL string is unmarshaled as a URL.
102+
func (o *OrchestratorLocalInfo) UnmarshalJSON(data []byte) error {
103+
type Alias OrchestratorLocalInfo
104+
aux := &struct {
105+
URL string `json:"Url"`
106+
*Alias
107+
}{
108+
Alias: (*Alias)(o),
109+
}
110+
if err := json.Unmarshal(data, aux); err != nil {
111+
return err
112+
}
113+
parsedURL, err := url.Parse(aux.URL)
114+
if err != nil {
115+
return err
116+
}
117+
o.URL = parsedURL
118+
return nil
119+
}
120+
100121
type ScorePred = func(float32) bool
101122
type OrchestratorPool interface {
102123
GetInfos() []OrchestratorLocalInfo

0 commit comments

Comments
 (0)