Skip to content

Commit

Permalink
updated golang readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro100 committed May 28, 2024
1 parent 9ac4097 commit ab46baa
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions models/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,37 @@ Using the pre-build unmarshaller
import(
"net/http"
"io"
v30systemInformation "github.com/MobilityData/gbfs-language-bindings/golang/v3.0/system_information"
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
)
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
resp, err := http.Get(url)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
systemInformationData, unmarshalError = v30systemInformation.UnmarshalSystemInformation(body)
systemInformationData, unmarshalError := v30systemInformation.UnmarshalSystemInformation(body)
if unmarshalError != nil {
// NOTE: If any type mismatch occurs (ex: number instead of string) it will show up as an error
fmt.Println("Error unmarshelling:", err)
return
}
// systemInformationData is now typed as SystemInformation
```
Or you can do it manually
```go
import(
"net/http"
"encoding/json"
"io"
v30systemInformation "github.com/MobilityData/gbfs-language-bindings/golang/v3.0/system_information"
v30systemInformation "github.com/MobilityData/gbfs-json-schema/models/golang/v3.0/system_information"
)
const url = "https://data-sharing.tier-services.io/tier_paris/gbfs/3.0/system-information";
resp, err := http.Get(url)
resp, errHttp := http.Get(url)
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
body, errRead := io.ReadAll(resp.Body)

var systemInformationData v30systemInformation.SystemInformation
err = json.Unmarshal(body, &systemInformationData)
if err != nil {
errMarshel := json.Unmarshal(body, &systemInformationData)
if errMarshel != nil {
// NOTE: If any type mismatch occurs (ex: number instead of string) it will show up as an error
fmt.Println("Error unmarshaling JSON:", err)
return
}

// systemInformationData is now typed as SystemInformation
Expand Down

0 comments on commit ab46baa

Please sign in to comment.