2024-04-08 21:50:52 +07:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-05-08 19:51:49 +07:00
|
|
|
"net/url"
|
2024-04-08 21:50:52 +07:00
|
|
|
|
|
|
|
"github.com/tigorlazuardi/redmage/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Context struct {
|
|
|
|
Config *config.Config
|
|
|
|
Request *http.Request
|
2024-05-08 19:51:49 +07:00
|
|
|
Query url.Values
|
2024-04-08 21:50:52 +07:00
|
|
|
}
|
|
|
|
|
2024-04-29 22:47:57 +07:00
|
|
|
func (c *Context) AppendQuery(keyValue ...string) string {
|
|
|
|
query := c.Request.URL.Query()
|
|
|
|
for i := 0; i < len(keyValue); i += 2 {
|
|
|
|
query.Add(keyValue[i], keyValue[i+1])
|
|
|
|
}
|
|
|
|
return query.Encode()
|
|
|
|
}
|
|
|
|
|
2024-04-08 21:50:52 +07:00
|
|
|
func NewContext(config *config.Config, request *http.Request) *Context {
|
|
|
|
return &Context{
|
|
|
|
Config: config,
|
|
|
|
Request: request,
|
2024-05-08 19:51:49 +07:00
|
|
|
Query: request.URL.Query(),
|
2024-04-08 21:50:52 +07:00
|
|
|
}
|
|
|
|
}
|