simple-ddns-client/internal/utils.go
Fijxu e63ab9a14d
All checks were successful
golangci-lint / lint (push) Successful in 38s
feat: option to add own IP api, and better error checks
2025-01-26 18:06:15 -03:00

49 lines
769 B
Go

package utils
import (
"bytes"
"io"
"net/http"
)
var client = &http.Client{}
func DoGetRequest(url string) ([]byte, error) {
request, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
res, err := client.Do(request)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
return body, nil
}
func DoPostRequest(url string, data []byte) ([]byte, error) {
request, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
if err != nil {
return nil, err
}
res, err := client.Do(request)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
return body, nil
}