Manage message in url param
This commit is contained in:
parent
dbe2f72344
commit
892ab64064
1 changed files with 20 additions and 0 deletions
20
response.go
20
response.go
|
|
@ -9,10 +9,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Response represents an HTTP response to be sent to the client, including headers, body, status code, and metadata.
|
// Response represents an HTTP response to be sent to the client, including headers, body, status code, and metadata.
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
FlashMessage string
|
||||||
|
MsgType string
|
||||||
headers []header
|
headers []header
|
||||||
body []byte
|
body []byte
|
||||||
statusCode int
|
statusCode int
|
||||||
|
|
@ -144,6 +147,23 @@ func (rs *Response) Redirect(url string) *Response {
|
||||||
}, map[string]interface{}{
|
}, map[string]interface{}{
|
||||||
"url": "url",
|
"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 v.Failed() {
|
||||||
if url[0:1] != "/" {
|
if url[0:1] != "/" {
|
||||||
rs.redirectTo = "/" + url
|
rs.redirectTo = "/" + url
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue