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

Handle case where mac_list is {} in Switch Status API response #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
7 changes: 6 additions & 1 deletion fbx/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func NewFreeboxHttpClient() *FreeboxHttpClient {

func (f *FreeboxHttpClient) Get(url string, out interface{}, callbacks ...FreeboxHttpClientCallback) error {
req, err := http.NewRequestWithContext(f.ctx, "GET", url, nil)

if err != nil {
return err
}
Expand Down Expand Up @@ -114,6 +113,12 @@ func (f *FreeboxHttpClient) do(req *http.Request, out interface{}) error {
}{
Result: out,
}

// Workaround for Switch Status API: mac_list is supposed to be an array. However, it is sometimes
// missing (which is fine), or an empty object `{}`, which causes json.Unmarshal to fail as it is
// expeting an array. This seems to be happening with sfp_lan.
body = bytes.Replace(body, []byte(`"mac_list":{}`), []byte(`"mac_list":[]`), 1)

if err := json.Unmarshal(body, &result); err != nil {
return err
}
Expand Down