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