From a48929d9396bf119ec696225618619f41c05f0b4 Mon Sep 17 00:00:00 2001 From: Thomas Bennett Date: Thu, 5 May 2016 15:00:13 -0700 Subject: [PATCH] added API key check and removed duplicate lines --- halo/go-halo5-api.go | 25 +++++++------------------ main.go | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/halo/go-halo5-api.go b/halo/go-halo5-api.go index 3b1d60f..0864a74 100644 --- a/halo/go-halo5-api.go +++ b/halo/go-halo5-api.go @@ -257,8 +257,7 @@ func metadataRequest(baseurl, title, datatype, id string) string { func sendRequest(url string) string { request, err := http.NewRequest("GET", url, nil) checkErr(err) - apikey := os.Getenv("HALO_API_KEY") - request.Header.Set("Ocp-Apim-Subscription-Key", apikey) + request.Header.Set("Ocp-Apim-Subscription-Key", getAPIKey()) response, err := http.DefaultClient.Do(request) checkErr(err) @@ -269,20 +268,10 @@ func sendRequest(url string) string { return string(contents) } -// Sample values for testing -var sampleGamertag string = "motta13" -var sampleMode string = "warzone" -var sampleMatchID string = "c35a35f8-f450-4836-a4c2-65100a7acb79" -var sampleSeasonID string = "b46c2095-4ca6-4f4b-a565-4702d7cfe586" //February 2016 Season -var samplePlaylistID string = "2323b76a-db98-4e03-aa37-e171cfbdd1a4" //SWAT gametype 2016 Season -var samplePlayers string = "motta13,smoke721" - -func main() { - // Uncomment any of the below for sample output. - //fmt.Println(matches_for_player(baseurl, title, SampleGamertag, "warzone", 0, 0)) - //fmt.Println(events_for_match(baseurl, title, sampleMatchID)) - //fmt.Println(player_leaderboard(baseurl, title, sampleSeasonID, samplePlaylistID, 0)) - //fmt.Println(service_record_arena(baseurl, title, samplePlayers, sampleSeasonID)) - //fmt.Println(vehicles(baseurl, title)) - //fmt.Println(spartan_image(baseurl, title, gamertag, 0, "")) +func getAPIKey() string { + apikey := os.Getenv("HALO_API_KEY") + if len(apikey) != 32 { + fmt.Println("Invalid API Key") + } + return apikey } diff --git a/main.go b/main.go index fafd40b..b7e84d7 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/dmmcquay/go-halo5-api/halo" + "github.com/tbenz9/go-halo5-api/halo" ) var baseurl string = "https://www.haloapi.com"