light modification

This commit is contained in:
mr 2025-01-22 15:03:40 +01:00
parent 4be954a6f3
commit 9c71730d9c

View File

@ -3,6 +3,7 @@ package tools
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -90,14 +91,20 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
} }
// CallPost calls the POST method on the HTTP server // CallPost calls the POST method on the HTTP server
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}, types ...string) ([]byte, error) { func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{}, types ...string) ([]byte, error) {
postBody, _ := json.Marshal(body) postBody, err := json.Marshal(body)
if err != nil {
fmt.Println(postBody)
return nil, err
}
responseBody := bytes.NewBuffer(postBody) responseBody := bytes.NewBuffer(postBody)
fmt.Println(responseBody)
contentType := "application/json" contentType := "application/json"
if len(types) > 0 { if len(types) > 0 {
contentType = types[0] contentType = types[0]
} }
resp, err := http.Post(url+subpath, contentType, responseBody) resp, err := http.Post(url+subpath, contentType, responseBody)
fmt.Println(resp, err)
if err != nil || resp == nil || resp.Body == nil { if err != nil || resp == nil || resp.Body == nil {
return nil, err return nil, err
} }