4 Commits

Author SHA1 Message Date
Bastian de Byl
913a8d1d9c moved module to json/helper 2023-02-26 15:20:33 -05:00
Bastian de Byl
8cec06641b added missing Accept header in Put() 2023-02-26 02:46:38 -05:00
Bastian de Byl
2ec64dc92b fixed Put function via revert 2023-02-26 02:35:43 -05:00
Bastian de Byl
3ceb440acc added missing Content-Type to Put and Post 2023-02-26 02:32:20 -05:00

View File

@@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
) )
@@ -17,6 +16,7 @@ func Get(uri string, authName string, authValue string, queries map[string]strin
client := &http.Client{} client := &http.Client{}
request.Header.Set("Accept", "application/json") request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue))
if len(queries) > 0 { if len(queries) > 0 {
@@ -37,7 +37,7 @@ func Get(uri string, authName string, authValue string, queries map[string]strin
return response, nil return response, nil
} }
func Post(uri string, authName string, authValue string, data io.Reader) (*http.Response, error) { func Post(uri string, authName string, authValue string, data any) (*http.Response, error) {
jsonBytes, err := json.Marshal(data) jsonBytes, err := json.Marshal(data)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -51,6 +51,7 @@ func Post(uri string, authName string, authValue string, data io.Reader) (*http.
client := &http.Client{} client := &http.Client{}
request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json") request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue))
@@ -62,7 +63,7 @@ func Post(uri string, authName string, authValue string, data io.Reader) (*http.
return response, nil return response, nil
} }
func Put(uri string, authName string, authValue string, data io.Reader) (*http.Response, error) { func Put(uri string, authName string, authValue string, data any) (*http.Response, error) {
jsonBytes, err := json.Marshal(data) jsonBytes, err := json.Marshal(data)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -77,6 +78,7 @@ func Put(uri string, authName string, authValue string, data io.Reader) (*http.R
client := &http.Client{} client := &http.Client{}
request.Header.Set("Content-Type", "application/json") request.Header.Set("Content-Type", "application/json")
request.Header.Set("Accept", "application/json")
request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue)) request.Header.Set("Authorization", fmt.Sprintf("%s %s", authName, authValue))
response, err := client.Do(request) response, err := client.Do(request)