installed gin
This commit is contained in:
@@ -4,9 +4,13 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Write(w http.ResponseWriter, r *http.Request, res Response) {
|
||||
func Write(c *gin.Context, res Response) {
|
||||
w := c.Writer
|
||||
|
||||
// w.Header() must be set before ResponseWriter.WriteHeader is called
|
||||
// or redirect is attempted
|
||||
hdrs := w.Header()
|
||||
@@ -19,7 +23,7 @@ func Write(w http.ResponseWriter, r *http.Request, res Response) {
|
||||
}
|
||||
|
||||
if code, to, ok := res.GetRedirect(); ok {
|
||||
http.Redirect(w, r, to, code.Int())
|
||||
http.Redirect(w, c.Request, to, code.Int())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,8 +51,8 @@ func Write(w http.ResponseWriter, r *http.Request, res Response) {
|
||||
|
||||
}
|
||||
|
||||
func WriteError(w http.ResponseWriter, err error) {
|
||||
http.Error(w, err.Error(), GetStatusFromError(err))
|
||||
func WriteError(c *gin.Context, err error) {
|
||||
c.String(GetStatusFromError(err), err.Error())
|
||||
}
|
||||
|
||||
func GetStatusFromError(err error) int {
|
||||
|
||||
Reference in New Issue
Block a user