Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 03 01:30
    hoslo opened #606
  • Dec 02 09:58
    jialechan commented #218
  • Nov 29 17:56
    MicBun opened #605
  • Nov 26 23:10
    sounddroid commented #589
  • Nov 26 22:42
    raharper commented #589
  • Nov 26 22:18
    raharper commented #589
  • Nov 25 07:25
    dandyhuang opened #603
  • Nov 23 13:50
    tenyuuk closed #602
  • Nov 23 11:23
    tenyuuk edited #602
  • Nov 23 11:22
    tenyuuk opened #602
  • Nov 14 22:54
    bjornbyte opened #601
  • Nov 10 15:16
    Joseph94m opened #600
  • Nov 10 07:32
    janekolszak commented #494
  • Nov 08 14:01
    saeedgeek opened #599
  • Nov 07 09:58
    saeedgeek reopened #598
  • Nov 07 09:58
    saeedgeek closed #598
  • Nov 07 08:54
    saeedgeek opened #598
  • Nov 04 15:32
    jameshoulahan edited #597
  • Nov 04 15:31
    jameshoulahan edited #597
  • Nov 04 15:26
    jameshoulahan opened #597
Jeevanandam M.
@jeevatkm
@jangaraj Could you try this?
// oauth2 lib part here
customClient := &http.Client{
    Transport: &http.Transport{
        TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    },
}

token := &oauth2.Token{
        AccessToken: "access token here",
        TokenType:   "bearer",
}

ctx := context.WithValue(context.Background(), oauth2.HTTPClient, customClient)
client := conf.Client(ctx, token)


// resty part starts here
rc := resty.NewWithClient(client)
Cameron Moore
@moorereason
@jeevatkm, what you think about factoring out all global state in v2, particularly DefaultClient? https://peter.bourgon.org/blog/2017/06/09/theory-of-modern-go.html
Jeevanandam M.
@jeevatkm
@moorereason Thanks for the input. I will read that article and get back to you.
Jeevanandam M.
@jeevatkm
@moorereason I have read that article and understand what it trying to convey.
Currently resty has similar approach of Go http client. Changing is not a big deal; basically removing defaultclient and would make resty as to create a client to use it. I would like to think about the benefits and downsides.
Grehgous
@Grehgous
When doing R().SetBody() on []byte it seems to automatically convert to base64 before the Post(). How do I bypass that so it stays in binary format?
Jeevanandam M.
@jeevatkm
@Grehgous Post body is sent as []byte, Resty does change that. However while doing debug log it does coverts to base64.
Jeevanandam M.
@jeevatkm
@/all ANN: go-resty v1.12.0 released!
Jeevanandam M.
@jeevatkm
@/all Resty v2 release plan and Create migration guide from v1 to v2 go-resty/resty#235
Jesse Farinacci
@jessefarinacci
hi :) i've been looking around for an example for resty post with large file data payload, must i really read the entire file into a byte array and then setbody on it? is there some way i can pass in a reference of some sort for resty to nicely stream the data as fast as it can?
Jesse Farinacci
@jessefarinacci
ah, ok, looks like it can take an io.Reader soo... request.SetBody(os.Open("myfile.txt")) may work
thanks for a great library :) appreciate it
Jeevanandam M.
@jeevatkm
@jessefarinacci Thank you :smile: . Yes you have found it correct. io.Reader way to go for your need.
modars
@modars_gitlab
Hi, I want Resty to stop to retry when got a certain types of error.
As far as I know, in Backoff(), Restry just restarts if it got an error from the operation regardless the result of my own retryCondition function.
How can I do this? Thank you
Jeevanandam M.
@jeevatkm
@modars_gitlab Could you please describe certain type of error? I think you could control the retry is needed or not from retry condition func.
modars
@modars_gitlab
@jeevatkm RESTY 2019/04/16 13:00:25 ERROR unexpected end of JSON input, Attempt 1 like this one.
func(r *resty.Response) (needRetry bool, err error) {
    return false, nil
}
I set retry condition like above for testing. This condition was executed but Resty still tried retry
modars
@modars_gitlab
I think because of this (from resty.v1/retry.go Backoff()):
if err == nil && !needsRetry && conditionErr == nil {
Jeevanandam M.
@jeevatkm
@modars_gitlab I think your guess is correct. This scenario is addressed in the Resty v2 implementation. Would you mind trying v2.0.0-rc.2, refer to go-resty/resty#235
modars
@modars_gitlab
@jeevatkm oh i found this pr go-resty/resty#237
I will try v2.0.0-rc.2 Thank you for your help :D
Jeevanandam M.
@jeevatkm
Thank you @modars_gitlab
Luc Stepniewski
@lstep

Hello, I can't find any way to retrieve/fill a stucture with SetResult() when the original JSON object root is a list.
For example, with curl, I get :

# curl -X POST -H Content-Type:application/json -d '{ "command": "version-get" }' http://localhost:8080
[ { "arguments": { "extended": "1.5.0\ntarball\nlinked with:\nlog4cplus 1.1.2\n" }, "result": 0, "text": "1.5.0" } ]

And my code :

type AutoGenerated []struct {
    Arguments struct {
        Extended string `json:"extended"`
    } `json:"arguments"`
    Result int    `json:"result"`
    Text   string `json:"text"`
}

resp, err := resty.R().
        SetBody(`{"command": "version-get"}`).
        SetResult(&AutoGenerated{}).
        Post("http://" + ip + ":" + strconv.Itoa(port))

fmt.Printf("%#v\n", resp.Result().(*AutoGenerated))
I always get an empty result
Jeevanandam M.
@jeevatkm
@lstep I will check and get back to you
Jeevanandam M.
@jeevatkm

ANN: go-resty v2.0.0 released! https://github.com/go-resty/resty

Please check it out and share your feedback :smile:

Jonathan Schweder
@jaswdr
is there any way to disable x509 certificate verification in the resty instance?
Jeevanandam M.
@jeevatkm
ANN: go-resty v2.1.0 released! https://github.com/go-resty/resty
Phat Nguyen
@fuatto
Hello @jeevatkm, is the issue from @lstep solved?
Jeevanandam M.
@jeevatkm
ANN: go-resty v2.2.0 released! https://github.com/go-resty/resty
Ovidiu-Florin BOGDAN
@madpipeline

Hello world. I'm trying to get a basic REST client running and I'm having issues Decoding the JSON response.

    client := resty.New()
    client.SetBasicAuth(os.Getenv("ARTIFACTORY_USER"), os.Getenv("ARTIFACTORY_PASSWORD"))
    rc := new(artifactory.ReplicationConfiguration)

    req := client.NewRequest()
    req.SetResult(rc)
    resp, _ := req.Get(oldArtyURL + "/api/replications/replicate-test")

    // json.NewDecoder(resp.RawBody()).Decode(rc)

    fmt.Println(resp)
    fmt.Println(rc.URL)
type ReplicationConfiguration struct {
    Username               string `json:"username,omitempty"` // Only in Local Repository
    Password               string `json:"password,omitempty"` // Only in Local Repository
    CronExp                string `json:"cronExp,omitempty"`
    URL                    string `json:"url"` // Only in Local Repository
    RepoKey                string `json:"repoKey,omitempty"`
    SockerTimeoutMillis    int    `json:"socketTimeoutMillis,omitempty"` // Only in Local Repository
    EnableEventReplication bool   `json:"enableEventReplication,omitempty"`
    Enabled                bool   `json:"enabled,omitempty"`
    SyncDeletes            bool   `json:"syncDeletes,omitempty"`
    SyncProperties         bool   `json:"syncProperties,omitempty"`
    SyncStatistics         bool   `json:"syncStatistics,omitempty"`
    PathPrefix             string `json:"pathPrefix,omitempty"`
}

With this I'm getting the responce on, I cna print it, but I get an empty object from decoding the response.

The responce gets printed as a list with one object. Could that affect the decoding?
I've tried decoding it both via the req.SetResult() method and via just using the json.NewDecoder() method. Both result in an empty object. Not sure what I'm doing wrong here
Ovidiu-Florin BOGDAN
@madpipeline
@jeevatkm do you have any suggestions?
Ovidiu-Florin BOGDAN
@madpipeline
I've solved it by sending var rcList []ReplicationConfiguration to the json.Decode and then retrieving the first object
andrewnprice
@andrewnprice
So ummm yeah, "Hi!" I am probably being a complete idiot about this, but could someone please explain how you are supposed to extract data once you get it back from your response? I have been messing with it for the last 6 hours or so, tried looking for examples, and in the source, but I am new to Go and I can't quite figure it out.
I might add, that might be something you want to address in the documentation since it is something that seems to come up from time to time. That said, your primary examples with regards to ingress applications are quite well composed and extremely useful.
Max Melkonian
@mmelk057

I think I found a solution to @lstep 's issue

Automatic unmarshalling (or from Java land - deserialization), from what I understand, is primarily dependent on the response Content-Type header.

Ever since resty v2.4.0, there's this new function called ForceContentType that gives developers more control to execute the unmarshalling process - it receives the highest precedence.

Associated PR: https://github.com/go-resty/resty/pull/371/files

resp, err := resty.R().
                                 SetBody(`{"command": "version-get"}`).
                                 SetResult(&AutoGenerated{}).
                                 ForceContentType("application/json").
                                 Post("http://" + ip + ":" + strconv.Itoa(port))

I had the exact same problem as @lstep : the object root of my JSON was a list. I was losing my mind trying to figure out what it could be. Anyways, this is what I came up with.

@madpipeline , @fuatto , tagging you guys too just in case you might get some value as well :)

Cheers!

Ryan Rowe
@rfrowe

Hi there. I've got a situation where I deal with an API that will return 200 OK with a JSON error payload. Right now I get perform my request using:

request := c.restyClient.R().
    SetHeaders(headers).
    SetQueryParams(input.QueryStringMap).
    SetFormData(input.FormData).
    SetBody(input.Body).
    SetResult(result)

Best way I can figure is to raise an error if an errors or error field is present on the JSON response object, but I can only have one result type. Is the best option just to add an errors and error field to my struct definition and throw an error if they're non-nill? Curious if anyone has had to deal with something like this before

Joe Cranney
@jj0e
Hey, I'm looking to use the uTLS https://github.com/refraction-networking/utls along with resty. How can I go about using the UConn connection with resty? I have looked through the docs and can't seem to find a way.
Ram
@8arcturus
Hi, Is there anyway to specify time format while using SetResult() ? I'm getting "parsing time ..." error.
wukong0111
@wukong0111
Is this project alive?
Dmitry
@Rikcon
Hello, can somebody please take a look, im struggling with sending post request with nested maps
[
'order' => ['ID' => 'ASC'],
'filter' => ['>ID' => $leadID],
'select' => ['ID', 'TITLE', 'DATE_CREATE'],
'start' => -1
]
i need to send smth like this, this is php code ^^^^^
image.png
this is golang resty code, i tried many different thing, if someone can throw me a piece of similar code i'll be very grateful )
main question is how do i do 'filter' => ['>ID' => $leadID], with golang
Dmitry
@Rikcon
nvm solved it
SetBody(map[string]interface{}{
"auth": authToken,
"filter": map[string]string{
">ID": strconv.FormatInt(leadId, 10),
},
"start": "-1",
}).
Jordan Taylor
@JustJordanT
Trying to create a custom auth header, am I able to do this?
Something like the following...
request.Header.Add("AUTH-API-KEY", "APIKEY")