Skip to content

Commit c26fd98

Browse files
committed
rename json functions
1 parent 9ec9b7c commit c26fd98

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

gttp/http.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func getTimeout(timeout ...time.Duration) time.Duration {
5454

5555
// Post sends a POST request to the specified URL.
5656
func Post(url string, headers M, body any, timeout ...time.Duration) (res *Response, err error) {
57-
req, err := http.NewRequest("POST", url, bytes.NewBuffer(helpers.ToJSON(body)))
57+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(helpers.ToBytes(body)))
5858
if err != nil {
5959
return
6060
}
@@ -112,7 +112,7 @@ func Get(url string, headers M, timeout ...time.Duration) (res *Response, err er
112112

113113
// Custom sends a custom request to the specified URL.
114114
func Custom(url, method string, headers M, body any, timeout ...time.Duration) (res *Response, err error) {
115-
req, err := http.NewRequest(method, url, bytes.NewBuffer(helpers.ToJSON(body)))
115+
req, err := http.NewRequest(method, url, bytes.NewBuffer(helpers.ToBytes(body)))
116116
if err != nil {
117117
return
118118
}

helpers/json.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/ochom/gutils/logs"
77
)
88

9-
// ToJSON converts a struct to JSON
10-
func ToJSON(payload any) []byte {
9+
// ToBytes converts provided interface to slice of bytes
10+
func ToBytes(payload any) []byte {
1111
if payload == nil {
1212
return nil
1313
}
@@ -31,8 +31,8 @@ func ToJSON(payload any) []byte {
3131
return bytesPayload
3232
}
3333

34-
// FromJSON converts json byte to struct
35-
func FromJSON[T any](payload []byte) T {
34+
// FromBytes converts slice of bytes to provided interface
35+
func FromBytes[T any](payload []byte) T {
3636
var data T
3737
if payload == nil {
3838
return data

0 commit comments

Comments
 (0)