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

Method request

ddns/porkbun.go:164–192  ·  view source on GitHub ↗

request 统一请求接口

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

Source from the content-addressed store, hash-verified

162
163// request 统一请求接口
164func (pb *Porkbun) request(url string, data interface{}, result interface{}) (err error) {
165 jsonStr := make([]byte, 0)
166 if data != nil {
167 jsonStr, _ = json.Marshal(data)
168 }
169 req, err := http.NewRequest(
170 "POST",
171 url,
172 bytes.NewBuffer(jsonStr),
173 )
174 if err != nil {
175 log.Println("http.NewRequest失败. Error: ", err)
176 return
177 }
178 req.Header.Set("Content-Type", "application/json")
179
180 client, e := pb.CreateHTTPClient()
181 if e != nil {
182 err = e
183 return
184 }
185
186 resp, err := client.Do(req)
187 if err != nil {
188 return err
189 }
190
191 return httputils.GetAndParseJSONResponseFromHttpResponse(resp, result)
192}

Callers 3

createUpdateDomainMethod · 0.95
createMethod · 0.95
modifyMethod · 0.95

Calls 3

MarshalMethod · 0.80
CreateHTTPClientMethod · 0.45

Tested by

no test coverage detected