request/v2/json.go
Matheus Sampaio Queiroga df0d1980f0 Delete request/v1 and Refactor request/{v2,gohtml} (#28)
Co-authored-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
Co-committed-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-02-27 15:03:57 +00:00

23 lines
493 B
Go

package request
import (
"encoding/json"
"net/http"
)
// Make request and process Body in target
func DoJSON(Url string, v any, Option *Options) (*http.Response, error) {
res, err := Request(Url, Option)
if err != nil {
return res, err
}
defer res.Body.Close()
return res, json.NewDecoder(res.Body).Decode(v)
}
// Make request and return struct body
func JSON[T any](Url string, Option *Options) (v T, res *http.Response, err error) {
res, err = DoJSON(Url, &v, Option)
return
}