mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2025-04-18 06:56:56 +00:00
Compare commits
No commits in common. "master" and "v0.2.3" have entirely different histories.
@ -53,12 +53,11 @@ func UploadPost(BasePath string, headers map[string]string, PostData UploadPostM
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@ -100,12 +99,11 @@ func NetworkStoragePut(URL string, ContentType string, filepath string) ([]byte,
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
@ -129,15 +127,13 @@ func UploadProcessPost(BasePath string, headers map[string]string, PostData Uplo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
_, err := io.Copy(buffer, resp.Body)
|
||||
BodyRead, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buffer.Bytes(), nil
|
||||
return BodyRead, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -75,5 +75,5 @@ func HTTPClientDo(Request *http.Request) (*http.Response, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
return response, err
|
||||
}
|
||||
|
@ -2,28 +2,18 @@ package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ResponseBuild(w http.ResponseWriter, ContentType string, ContentData []byte) {
|
||||
w.Header().Set("Content-Type", ContentType)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(ContentData)
|
||||
}
|
||||
|
||||
func ErrorResponseBuild(w http.ResponseWriter, StatusCode int64, Message string) {
|
||||
func ErrorResponseBuild(StatusCode int64, Message string) string {
|
||||
ErrorResponse := ErrorResponse{
|
||||
StatusCode: StatusCode,
|
||||
Message: Message,
|
||||
}
|
||||
Response, _ := json.Marshal(ErrorResponse)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(int(StatusCode))
|
||||
w.Write(Response)
|
||||
return string(Response)
|
||||
}
|
||||
|
||||
func InfoLogBuilder(headers []string, message string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user