mirror of https://github.com/goproxyio/goproxy
30 lines
641 B
Go
30 lines
641 B
Go
package proxy
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
var errLogger = log.New(os.Stderr, "", log.LstdFlags)
|
|
|
|
func ReturnInternalServerError(w http.ResponseWriter, err error) {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
msg := fmt.Sprintf("%v", err)
|
|
errLogger.Printf("goproxy: %s\n", msg)
|
|
_, _ = w.Write([]byte(msg))
|
|
}
|
|
|
|
func ReturnBadRequest(w http.ResponseWriter, err error) {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
msg := fmt.Sprintf("%v", err)
|
|
errLogger.Printf("goproxy: %s\n", msg)
|
|
_, _ = w.Write([]byte(msg))
|
|
}
|
|
|
|
func ReturnSuccess(w http.ResponseWriter, data []byte) {
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write(data)
|
|
}
|