Merge pull request #625 from trheyi/main
[add] support for retrieving cookies in sui Request struct
This commit is contained in:
commit
b8d6c3a539
3 changed files with 17 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -39,4 +39,5 @@ xgen/v1.0/*
|
||||||
!xgen/v1.0/layouts__index.async.js
|
!xgen/v1.0/layouts__index.async.js
|
||||||
!pipe/ui
|
!pipe/ui
|
||||||
*-unit-test
|
*-unit-test
|
||||||
docker/build/test
|
docker/build/test
|
||||||
|
db
|
||||||
|
|
@ -213,6 +213,7 @@ func (r *Request) Render() (string, int, error) {
|
||||||
data["$payload"] = r.Request.Payload
|
data["$payload"] = r.Request.Payload
|
||||||
data["$query"] = r.Request.Query
|
data["$query"] = r.Request.Query
|
||||||
data["$param"] = r.Request.Params
|
data["$param"] = r.Request.Params
|
||||||
|
data["$cookie"] = r.Request.Cookies()
|
||||||
data["$url"] = r.Request.URL
|
data["$url"] = r.Request.URL
|
||||||
|
|
||||||
printData := false
|
printData := false
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,20 @@ func NewRequestMock(mock *PageMock) *Request {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cookies get the cookies
|
||||||
|
func (r *Request) Cookies() map[string]string {
|
||||||
|
cookies := map[string]string{}
|
||||||
|
cookie := r.Headers.Get("Cookie")
|
||||||
|
parts := strings.Split(cookie, ";")
|
||||||
|
for _, part := range parts {
|
||||||
|
kv := strings.Split(strings.TrimSpace(part), "=")
|
||||||
|
if len(kv) == 2 {
|
||||||
|
cookies[kv[0]] = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cookies
|
||||||
|
}
|
||||||
|
|
||||||
// ExecString get the data
|
// ExecString get the data
|
||||||
func (r *Request) ExecString(data string) (Data, error) {
|
func (r *Request) ExecString(data string) (Data, error) {
|
||||||
var res Data
|
var res Data
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue