Hi, While others have been talking about headers, I notice that you are using the python requests 3rd party library, and referring to the "params" keyword arg which is meant to pass query string values in your GET request.
I would think the equivalent in Go would be to: 1. Build the equivalent of the python "params" dictionary using url.Values <https://golang.org/pkg/net/url/#Values> 2. Build your *url.Url <https://golang.org/pkg/net/url/#URL>, with that url.Values object 3. Build an *http.Request <https://golang.org/pkg/net/http/#Request> with that *url.Url 4. Run your GET request via http.Client.Do() <https://golang.org/pkg/net/http/#Client.Do> Justin On Wed, Dec 14, 2016 at 8:33 AM 'Chris Manghane' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I see, well that makes the compiler error make more sense. You're trying > to declare a function type within a function. Use a function literal > instead, for example: `doIT := func(p Params) string { ... }`. > > On Tue, Dec 13, 2016 at 11:18 AM, Betsy Lichtenberg <bet...@nestlabs.com> > wrote: > > The expression is inside of the main function. > > package main > > import ( > "fmt" > "strings" > "net/http" > "io/ioutil" > ) > > func main() { > > url := "https://developer-api.nest.com/structures" > > payload := > strings.NewReader("code=aaaaa&client_id=bbbb&client_secret=cccc&grant_type=authorization_code") > > req, _ := http.NewRequest("GET", url, payload) > > req.Header.Add("content-type", "application/json") > > type Params struct { > auth string > } > > func doIt(p Params) string { > return p.auth > } > > doIt(Params{auth: xxxx}) > > res, _ := http.DefaultClient.Do(req) > > defer res.Body.Close() > body, _ := ioutil.ReadAll(res.Body) > > fmt.Println(res) > fmt.Println(string(body)) > > } > > On Tue, Dec 13, 2016 at 11:13 AM, Chris Manghane <cm...@google.com> wrote: > > That error seems to be from writing that expression outside of a function. > There's no problem with structs supporting string fields: > https://play.golang.org/p/YeP2qhRdxp. > > On Tue, Dec 13, 2016 at 10:45 AM, Betsy Lichtenberg <bet...@nestlabs.com> > wrote: > > Do structs support strings? I tried this: > > type Params struct { > auth string > } > > func doIt(p Params) string { > return p.auth > } > > doIt(Params{auth: xxxx}) > > > I'm getting these errors: > > betsyl-macbookpro:~ betsyl$ go run get1.go > > # command-line-arguments > > ./get1.go:25: syntax error: unexpected doIt, expecting ( > > ./get1.go:29: syntax error: unexpected literal .2, expecting comma or } > > On Tue, Dec 13, 2016 at 7:11 AM, Val <delepl...@gmail.com> wrote: > > Hello Betsy > There is no "passing optional arguments by name" in go. > > This link [1] has an overview what what can or can't be done for optional > params : > - the *Functional options* technique. > - or you may define a struct as parameter, then call it with only the > fields you're interested in : [2] > This implies that "the zero values must be meaningful (i.e. acceptable in > your context : nil, 0, etc.)" > > things := Things{amount: 13} > show(things) > > [1] http://stackoverflow.com/questions/2032149/optional-parameters > [2] https://play.golang.org/p/yiKzomwTKM > > On Tuesday, December 13, 2016 at 6:46:23 AM UTC+1, bet...@google.com > wrote: > > Hi, > > In Python, I can include params like this: > > ===================== > > *params = {'auth': 'XXXXXXXX'}* > > response = requests.request("GET", url, data=payload, headers=headers, > *params=params*) > > ===================== > > Any pointers on how Golang does this? > > Thanks, > Betsy > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.