Skip to content

Instantly share code, notes, and snippets.

@BenHall
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHall/3fa11345256ee9575b2d to your computer and use it in GitHub Desktop.
Save BenHall/3fa11345256ee9575b2d to your computer and use it in GitHub Desktop.
func Get(id string, inter interface{}) {
baseUrl := "http://localhost:9200"
index := "fixtures"
url := fmt.Sprintf("%v/grandslam/%v/%v", baseUrl, index, id)
response, err := http.Get(url)
if err != nil {
fmt.Printf("Error: %s", err)
}
body, err2 := ioutil.ReadAll(response.Body)
if err2 != nil {
fmt.Printf("Error: %s", err2)
}
var parsed_resp ElasticGetResponse
json.Unmarshal(body, &parsed_resp)
fmt.Printf("ID: %s \r\n", parsed_resp.Source)
json.Unmarshal(parsed_resp.Source, &inter)
fmt.Printf("Data: %s", inter.Home)
}
type TestFixture struct {
Id int `json:"id"`
Home int `json:"home"`
Away int `json:"away"`
}
func TestGet_returns_data(t *testing.T) {
test_data := []TestFixture{
{ Id: 0, Home: 3, Away: 3 },
{ Id: 1, Home: 2, Away: 1 },
{ Id: 3, Home: 1, Away: 0 },
}
resp := Save(test_data[0]);
assert.Equal(t, resp.Ok, true)
var fixture TestFixture
Get(resp.Id, &fixture)
assert.Equal(t, fixture.Id, 3)
assert.Equal(t, fixture.Home, 3)
assert.Equal(t, fixture.Away, 3)
}
@BenHall
Copy link
Author

BenHall commented Aug 10, 2014

./sdk.go:73: cannot use parsed_resp.Source (type interface {}) as type []byte in function argument: need type assertion
./sdk.go:74: inter.Home undefined (type interface {} has no field or method Home)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment