{"action":"created","issue":{"url":"https://api.github.com/repos/parnurzeal/gorequest/issues/162","repository_url":"https://api.github.com/repos/parnurzeal/gorequest","labels_url":"https://api.github.com/repos/parnurzeal/gorequest/issues/162/labels{/name}","comments_url":"https://api.github.com/repos/parnurzeal/gorequest/issues/162/comments","events_url":"https://api.github.com/repos/parnurzeal/gorequest/issues/162/events","html_url":"https://github.com/parnurzeal/gorequest/pull/162","id":262518738,"node_id":"MDExOlB1bGxSZXF1ZXN0MTQ0NDgzNDIx","number":162,"title":"\"Clone\" the SuperAgent for reuse","user":{"login":"fromkeith","id":1834082,"node_id":"MDQ6VXNlcjE4MzQwODI=","avatar_url":"https://avatars1.githubusercontent.com/u/1834082?v=4","gravatar_id":"","url":"https://api.github.com/users/fromkeith","html_url":"https://github.com/fromkeith","followers_url":"https://api.github.com/users/fromkeith/followers","following_url":"https://api.github.com/users/fromkeith/following{/other_user}","gists_url":"https://api.github.com/users/fromkeith/gists{/gist_id}","starred_url":"https://api.github.com/users/fromkeith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fromkeith/subscriptions","organizations_url":"https://api.github.com/users/fromkeith/orgs","repos_url":"https://api.github.com/users/fromkeith/repos","events_url":"https://api.github.com/users/fromkeith/events{/privacy}","received_events_url":"https://api.github.com/users/fromkeith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-10-03T17:37:44Z","updated_at":"2018-11-15T10:07:17Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/parnurzeal/gorequest/pulls/162","html_url":"https://github.com/parnurzeal/gorequest/pull/162","diff_url":"https://github.com/parnurzeal/gorequest/pull/162.diff","patch_url":"https://github.com/parnurzeal/gorequest/pull/162.patch"},"body":"The aim of this is to allow a base gorequest to be re-used throughout someone's code base.\r\n\r\nIdeally, gorequest itself would be concurrent safe, but I think that would require much larger changes (and possibly API changes). This takes the approach of _Cloning_ the base gorequest, so it can be safely used by multiple routines at the same time.\r\n\r\nIn my scenario I run a web server. I want to be able to easily re-use a single gorequest base, that gets configured at startup (Eg. timeout, transport, auth, etc...). Adding the Clone method lets me do this safely without running into concurrency issues. \r\n\r\nWhile refactoring a bit a few other changes had to be made:\r\n1. The \"Timeout\" function points to the base gorequest. It also looks like it may have been written after http.Client.Timeout existed. So I switched it to that. Let me know if my assumption there is wrong.\r\n2. Try to \"safely\" manage any changes to http.Client & http.Transport. Ideally the user should not be allowed to edit the Client or Transport after calling Clone. However, that would break the API. So instead, I do a \"best effort\" clone of the Client and Transport so a clone cannot affect the base.\r\n\r\nAn example is provided in the readme, with this code example:\r\n```go\r\nbaseRequest := gorequest.New()\r\n// apply anything you want to these settings. Eg:\r\nbaseRequest.Timeout(10 * time.Millisecond).\r\n  BasicAuth(\"user\", \"password\")\r\n\r\n// then reuse the base request elsewhere, cloning before modifying or using it.\r\nresp, body, errs := baseRequest.Clone().Get(\"http://exmaple.com/\").End()\r\n```\r\n\r\nShould fix, or provide a workaround for\r\n#147 - Concurrent write access to a map. Clone makes new Header & Query maps. Should solve this issue.\r\n#125 - Clone allows the underlying Client and transport to be re-used.\r\n#73 - Calling Clone on the base allows for re-use\r\n#27 - Should fix most of the concurrency issues if Clone is used.\r\n\r\nLet me know what you think!"},"comment":{"url":"https://api.github.com/repos/parnurzeal/gorequest/issues/comments/438986636","html_url":"https://github.com/parnurzeal/gorequest/pull/162#issuecomment-438986636","issue_url":"https://api.github.com/repos/parnurzeal/gorequest/issues/162","id":438986636,"node_id":"MDEyOklzc3VlQ29tbWVudDQzODk4NjYzNg==","user":{"login":"lalit-verma","id":13415735,"node_id":"MDQ6VXNlcjEzNDE1NzM1","avatar_url":"https://avatars3.githubusercontent.com/u/13415735?v=4","gravatar_id":"","url":"https://api.github.com/users/lalit-verma","html_url":"https://github.com/lalit-verma","followers_url":"https://api.github.com/users/lalit-verma/followers","following_url":"https://api.github.com/users/lalit-verma/following{/other_user}","gists_url":"https://api.github.com/users/lalit-verma/gists{/gist_id}","starred_url":"https://api.github.com/users/lalit-verma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lalit-verma/subscriptions","organizations_url":"https://api.github.com/users/lalit-verma/orgs","repos_url":"https://api.github.com/users/lalit-verma/repos","events_url":"https://api.github.com/users/lalit-verma/events{/privacy}","received_events_url":"https://api.github.com/users/lalit-verma/received_events","type":"User","site_admin":false},"created_at":"2018-11-15T10:07:17Z","updated_at":"2018-11-15T10:07:17Z","author_association":"NONE","body":"@parnurzeal @QuentinPerez Guys Any update on this one ?\r\nDo you guys plan on merging this ?"}}
{"actor":{"display_login":"lalit-verma"}}