Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

json not being passed to request #125

Closed
warroyo opened this issue Feb 6, 2016 · 1 comment
Closed

json not being passed to request #125

warroyo opened this issue Feb 6, 2016 · 1 comment

Comments

@warroyo
Copy link

warroyo commented Feb 6, 2016

I am trying to make POST request with a json body. I have created a struct(see below) and i have set the debug output. Below is my code and results. it seems like the json is never getting parsed? the body is empty when i show the debug output.

code:

type NewServiceJson struct {
    name       string
    space_guid string
    credentials map[string]string
}

jsonvalue := NewServiceJson{name: serviceUpdates.Service.Name, space_guid: cfinfo.Space.Guid, credentials: serviceUpdates.Service.Credentials}
    res, err := goreq.Request{
        Method:    "POST",
        Uri:       cfinfo.ApiEndpoint + "/v2/user_provided_service_instances",
        Body:      jsonvalue,
        Accept:    "application/json",
        Insecure:  true,
        ShowDebug: true,
    }.WithHeader("Authorization", "Bearer "+cfinfo.BearerToken).Do()
    fmt.Println(res, err)


output:


016/02/05 17:16:38 POST /v2/user_provided_service_instances HTTP/1.1
Host: myhost.com
Accept: application/json
Authorization: Bearer [SECRET DATA REMOVED]
{}
&{0xc8200866c0  0xc8200c0740 0xc8200f81c0} <nil>

@marcosnils
Copy link
Member

@warroyo struct fields need to be public (first letter uppercased) so they can be marshalled

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants