diff --git a/response.go b/response.go index d6202c7..6beb36e 100644 --- a/response.go +++ b/response.go @@ -9,10 +9,13 @@ import ( "bytes" "fmt" "net/http" + "strings" ) // Response represents an HTTP response to be sent to the client, including headers, body, status code, and metadata. type Response struct { + FlashMessage string + MsgType string headers []header body []byte statusCode int @@ -144,6 +147,23 @@ func (rs *Response) Redirect(url string) *Response { }, map[string]interface{}{ "url": "url", }) + + if rs.FlashMessage != "" || rs.MsgType != "" { + if !strings.Contains(url, "?") { + url += "?" + } else { + url += "&" + } + if rs.FlashMessage != "" { + url += "flash_message=" + rs.FlashMessage + } + if rs.MsgType != "" { + if rs.FlashMessage != "" { + url += "&" + } + url += "msg_type=" + rs.MsgType + } + } if v.Failed() { if url[0:1] != "/" { rs.redirectTo = "/" + url