Last active
August 29, 2015 14:05
-
-
Save BenHall/3fa11345256ee9575b2d to your computer and use it in GitHub Desktop.
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
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) | |
} |
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
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./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)