by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 05 13:39
    moorereason commented #361
  • Aug 05 03:38
    codecov[bot] commented #362
  • Aug 05 03:34
    codecov[bot] commented #362
  • Aug 05 03:33
    codecov[bot] commented #362
  • Aug 05 03:33
    codecov[bot] commented #362
  • Aug 05 03:31
    codecov[bot] commented #362
  • Aug 05 03:29
    codecov[bot] commented #362
  • Aug 05 03:29
    moorereason synchronize #362
  • Aug 05 03:28
    codecov[bot] commented #362
  • Aug 05 03:27
    codecov[bot] commented #362
  • Aug 05 03:27
    moorereason synchronize #362
  • Aug 05 03:25
    codecov[bot] commented #362
  • Aug 05 03:21
    moorereason ready_for_review #362
  • Aug 05 03:21
    codecov[bot] commented #362
  • Aug 05 03:21
    moorereason synchronize #362
  • Aug 05 02:56
    codecov[bot] commented #363
  • Aug 05 02:53
    codecov[bot] commented #363
  • Aug 05 02:53
    codecov[bot] commented #363
  • Aug 05 02:49
    Alex1996a opened #363
  • Aug 05 02:21
    cascax commented #361
Joe Condlin
@Joe8792_twitter
Hello - I have a question. We're using go_resty in our product. We are trying to write some unit tests which will require us to create a mock response object. We are trying to do this by setting the RawResponse
to an http.Response object that we pre-populate with test data. The problem is that the response.Body is empty when we try to look at it. Is there a way we can create a mock response object, or is it not possible? Thanks.
Jeevanandam M.
@jeevatkm
@Joe8792_twitter Typically you could any mocking library of your choice with Resty. On resty readme there is mentioning about httpmock library https://github.com/go-resty/resty#mocking-http-requests-using-httpmock-library please have a look.
Joe Condlin
@Joe8792_twitter
Hi, thanks for responding. I think our problem is that we created a wrapper layer around resty for our REST operations. The wrapper methods we created return a resty response object. We are trying to figure out how to mock our methods to have them return a resty response we pre-populate.
Jeevanandam M.
@jeevatkm
@Joe8792_twitter If you have wrapper around Resty, I think its not an issue. Just you might have to update your wrapper design. For e.g.: Probably have your wrapper implemented with interface and have the implementation using that interface with actual response struct and mock response struct. So you could register actual and mock response on need basis.
Jan Garaj
@jangaraj
Hi, I have a problem to ignore TLS errors: &tls.Config{InsecureSkipVerify: true}
Resty error:
2019/01/21 19:44:13 ERROR current transport is not an *http.Transport instance
I'm not able to overwrite oauth client :(. Any advice?
Jan Garaj
@jangaraj
Resolved with custom context :-)
        tr := &http.Transport{
                TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
        }
        sslcli := &http.Client{Transport: tr}
        ctx := context.TODO()
        ctx = context.WithValue(ctx, oauth2.HTTPClient, sslcli)
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 André 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