Created
September 16, 2021 03:03
-
-
Save kgravenreuth/a84c89567007cc3ba9566aa6765805ad to your computer and use it in GitHub Desktop.
Cloudbet API Sports Fixtures in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "github.com/Cloudbet/docs/go/cloudbet" | |
const eventURL = "https://sports-api.cloudbet.com/pub/v2/odds/events/%v" | |
// … | |
req, err := http.NewRequest("GET", fmt.Sprintf(eventURL, 123456), nil) | |
if err != nil { | |
return err | |
} | |
req.Header.Set("accept", "application/json") | |
req.Header.Set("X-API-Key", "eyJ...") // <-- use your API key | |
req.Header.Set("Content-Type", "application/json") | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
return err | |
} | |
var event cloudbet.Event | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
return err | |
} | |
defer resp.Body.Close() | |
err = protojson.UnmarshalOptions{DiscardUnknown: true, AllowPartial: true}.Unmarshal(body, &event) | |
if err != nil { | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment