mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Make initial request setup in the external private function
This commit is contained in:
+22
-11
@@ -56,17 +56,7 @@ func (g *HTTPClient) doQuery(method string, v easyjson.Unmarshaler, params ...Qu
|
|||||||
fasthttp.ReleaseRequest(req)
|
fasthttp.ReleaseRequest(req)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
uri := req.URI()
|
g.setupRequest(method, req)
|
||||||
uri.SetHost(g.Addr)
|
|
||||||
uri.SetPath(method)
|
|
||||||
uri.QueryArgs().Add("key", g.ContentKey)
|
|
||||||
if g.client.IsTLS {
|
|
||||||
uri.SetScheme("https")
|
|
||||||
}
|
|
||||||
|
|
||||||
for hKey, hValue := range g.Headers {
|
|
||||||
req.Header.Add(hKey, hValue)
|
|
||||||
}
|
|
||||||
for _, param := range params {
|
for _, param := range params {
|
||||||
param.Apply(&req.Header, uri.QueryArgs())
|
param.Apply(&req.Header, uri.QueryArgs())
|
||||||
}
|
}
|
||||||
@@ -92,6 +82,27 @@ func (g *HTTPClient) doQuery(method string, v easyjson.Unmarshaler, params ...Qu
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setupRequest does the necessary initial configuration to the http request
|
||||||
|
func (g *HTTPClient) setupRequest(path string, req *fasthttp.Request) {
|
||||||
|
|
||||||
|
uri := req.URI()
|
||||||
|
|
||||||
|
scheme := "http"
|
||||||
|
if g.Secured {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
|
||||||
|
uri.SetHost(g.Addr)
|
||||||
|
uri.SetPath(path)
|
||||||
|
uri.SetScheme(scheme)
|
||||||
|
|
||||||
|
uri.QueryArgs().Add("key", g.ContentKey)
|
||||||
|
|
||||||
|
for hKey, hValue := range g.Headers {
|
||||||
|
req.Header.Add(hKey, hValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetPageBySlug returns the only one page using slug filter
|
// GetPageBySlug returns the only one page using slug filter
|
||||||
func (g *HTTPClient) GetPageBySlug(slug string) (pages *Pages, err error) {
|
func (g *HTTPClient) GetPageBySlug(slug string) (pages *Pages, err error) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user