More work on the library

json tags for all structs
This commit is contained in:
2019-04-08 16:25:31 -05:00
parent d56ccc469a
commit 432d44cbf5
14 changed files with 220 additions and 199 deletions

View File

@@ -3,40 +3,30 @@ package main
import (
"encoding/json"
"fmt"
"log"
"git.bullercodeworks.com/brian/openstates"
"github.com/machinebox/graphql"
)
func main() {
req := graphql.NewRequest(`
query Reps($lat: Float, $long: Float) {
people(latitude: $lat, longitude: $long, first: 100) {
edges {
node {
id
name
sortName
familyName
givenName
image
birthDate
deathDate
createdAt
updatedAt
extras
}
}
}
}
`)
req.Var("lat", 37.700824)
req.Var("long", -97.352906)
//req := graphql.NewRequest(`query Reps($lat:Float,$long:Float){people(latitude:$lat,longitude:$long,first:100){edges{node{id name sortName familyName givenName image birthDate deathDate createdAt updatedAt extras links}}}}`)
//req.Var("lat", 37.700824)
//req.Var("long")
var res response
o := openstates.NewOpenStatesApi(ApiKey)
o.TurnOnLogging()
o.MakeRequest(req, &res)
o.SetLogger(func(s string) { log.Println(s) })
props := make(map[string]interface{})
props["lat"] = 37.700824
props["long"] = -97.352906
o.MakeRequest(&res, props)
//o.MakeRequest(req, &res)
//fmt.Println("= Fields =")
//for _, v := range res.People.Edges {
// v.Node.GetFields()
// break
//}
fmt.Println("= Result =")
j, _ := json.Marshal(res)
fmt.Println(string(j))
}
@@ -48,7 +38,7 @@ type people struct {
Edges []edge
}
type edge struct {
Node node
Node openstates.PersonNode
}
type node struct {
Name string