shared peer conn
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user