Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct URL unmarshal error #3364

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading