shared peer conn

This commit is contained in:
mr
2024-08-13 09:49:42 +02:00
parent 6fe862a9b5
commit e71bd3544f
10 changed files with 237 additions and 24 deletions

View File

@@ -7,19 +7,24 @@ import (
"net/http"
)
type METHOD int
const (
GET METHOD = iota
PUT
POST
DELETE
)
var HTTPCallerInstance = &HTTPCaller{}
type HTTPCaller struct {
Origin string
OriginSubPath string
DestSubPath string
URLS map[string]map[METHOD]string
}
func NewHTTPCaller(url string, origin string, originSubPath string, destSubPath string) *HTTPCaller {
func NewHTTPCaller(urls map[string]map[METHOD]string) *HTTPCaller {
return &HTTPCaller{
Origin: origin,
OriginSubPath: originSubPath,
DestSubPath: destSubPath,
URLS: urls,
}
}
@@ -32,6 +37,15 @@ func (caller *HTTPCaller) CallGet(url string, subpath string) ([]byte, error) {
return io.ReadAll(resp.Body)
}
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
resp, err := http.NewRequest("DELETE", url+subpath, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}) ([]byte, error) {
postBody, _ := json.Marshal(body)
responseBody := bytes.NewBuffer(postBody)