mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2024-12-22 10:08:08 +00:00
chibisafe_netstorage_middleman : strcture refactor
This commit is contained in:
parent
cb89a40e72
commit
5bb04ab856
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
uploads
|
||||
uploads
|
||||
activity.log
|
File diff suppressed because it is too large
Load Diff
61
src/handler/httpdo.go
Normal file
61
src/handler/httpdo.go
Normal file
@ -0,0 +1,61 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func HTTPBytes(RequestStruct URLRequest, RequestData *bytes.Buffer) (*http.Response, error) {
|
||||
// Create a new request with POST method and request body
|
||||
req, err := http.NewRequest(RequestStruct.Method, RequestStruct.URL, RequestData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if RequestStruct.ContentLength != nil {
|
||||
req.ContentLength = int64(*RequestStruct.ContentLength)
|
||||
}
|
||||
|
||||
for key, value := range RequestStruct.Header {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
|
||||
resp, err := HTTPClientDo(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer RequestData.Reset()
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func HTTPOSFile(RequestStruct URLRequest, RequestData *os.File) (*http.Response, error) {
|
||||
// Create a new request with POST method and request body
|
||||
req, err := http.NewRequest(RequestStruct.Method, RequestStruct.URL, RequestData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if RequestStruct.ContentLength != nil {
|
||||
req.ContentLength = int64(*RequestStruct.ContentLength)
|
||||
}
|
||||
|
||||
for key, value := range RequestStruct.Header {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
|
||||
resp, err := HTTPClientDo(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func HTTPClientDo(Request *http.Request) (*http.Response, error) {
|
||||
client := &http.Client{}
|
||||
response, err := client.Do(Request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, err
|
||||
}
|
@ -23,3 +23,11 @@ type UploadProcessResponseMeta struct {
|
||||
UUID string `json:"uuid"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type URLRequest struct {
|
||||
URL string
|
||||
ContentType string
|
||||
Method string
|
||||
ContentLength *int
|
||||
Header map[string]string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user