Make initial request setup in the external private function

develop
Nikita Tokarchuk 3 years ago
parent 0b003c200a
commit 6311bf1dd7
Signed by: mainnika
GPG Key ID: A595FB7E3E56911C
  1. 33
      frontend/ghost/client.go

@ -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) {

Loading…
Cancel
Save