MCPcopy
hub / github.com/gdy666/lucky / request

Method request

ddns/cloudflare.go:198–226  ·  view source on GitHub ↗

request 统一请求接口

(method string, url string, data interface{}, result interface{})

Source from the content-addressed store, hash-verified

196
197// request 统一请求接口
198func (cf *Cloudflare) request(method string, url string, data interface{}, result interface{}) (err error) {
199 jsonStr := make([]byte, 0)
200 if data != nil {
201 jsonStr, _ = json.Marshal(data)
202 }
203 req, err := http.NewRequest(
204 method,
205 url,
206 bytes.NewBuffer(jsonStr),
207 )
208 if err != nil {
209 log.Println("http.NewRequest失败. Error: ", err)
210 return
211 }
212 req.Header.Set("Authorization", "Bearer "+cf.task.DNS.Secret)
213 req.Header.Set("Content-Type", "application/json")
214
215 client, err := cf.CreateHTTPClient()
216 if err != nil {
217 return err
218 }
219
220 resp, err := client.Do(req)
221 if err != nil {
222 return err
223 }
224
225 return httputils.GetAndParseJSONResponseFromHttpResponse(resp, result)
226}

Callers 4

createUpdateDomainMethod · 0.95
createMethod · 0.95
modifyMethod · 0.95
getZonesMethod · 0.95

Calls 3

MarshalMethod · 0.80
CreateHTTPClientMethod · 0.45

Tested by

no test coverage detected