Cosmetic changes:
- Deprecating GetCookie()
This commit is contained in:
parent
7afb3238a3
commit
4c639a5049
49
context.go
49
context.go
@ -189,15 +189,15 @@ func (c *Context) MustGet(key string) interface{} {
|
|||||||
// c.Query("id") == "1234"
|
// c.Query("id") == "1234"
|
||||||
// c.Query("name") == "Manu"
|
// c.Query("name") == "Manu"
|
||||||
// c.Query("wtf") == ""
|
// c.Query("wtf") == ""
|
||||||
func (c *Context) Query(key string) (va string) {
|
func (c *Context) Query(key string) string {
|
||||||
va, _ = c.query(key)
|
value, _ := c.query(key)
|
||||||
return
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostForm is a shortcut for c.Request.PostFormValue(key)
|
// PostForm is a shortcut for c.Request.PostFormValue(key)
|
||||||
func (c *Context) PostForm(key string) (va string) {
|
func (c *Context) PostForm(key string) string {
|
||||||
va, _ = c.postForm(key)
|
value, _ := c.postForm(key)
|
||||||
return
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Param is a shortcut for c.Params.ByName(key)
|
// Param is a shortcut for c.Params.ByName(key)
|
||||||
@ -206,8 +206,8 @@ func (c *Context) Param(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) DefaultPostForm(key, defaultValue string) string {
|
func (c *Context) DefaultPostForm(key, defaultValue string) string {
|
||||||
if va, ok := c.postForm(key); ok {
|
if value, ok := c.postForm(key); ok {
|
||||||
return va
|
return value
|
||||||
}
|
}
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
@ -220,8 +220,8 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string {
|
|||||||
// c.DefaultQuery("id", "none") == "none"
|
// c.DefaultQuery("id", "none") == "none"
|
||||||
// ```
|
// ```
|
||||||
func (c *Context) DefaultQuery(key, defaultValue string) string {
|
func (c *Context) DefaultQuery(key, defaultValue string) string {
|
||||||
if va, ok := c.query(key); ok {
|
if value, ok := c.query(key); ok {
|
||||||
return va
|
return value
|
||||||
}
|
}
|
||||||
return defaultValue
|
return defaultValue
|
||||||
}
|
}
|
||||||
@ -339,25 +339,22 @@ func (c *Context) SetCookie(
|
|||||||
secure bool,
|
secure bool,
|
||||||
httpOnly bool,
|
httpOnly bool,
|
||||||
) {
|
) {
|
||||||
cookie := http.Cookie{}
|
if path == "" {
|
||||||
cookie.Name = name
|
path = "/"
|
||||||
cookie.Value = url.QueryEscape(value)
|
|
||||||
|
|
||||||
cookie.MaxAge = maxAge
|
|
||||||
|
|
||||||
cookie.Path = "/"
|
|
||||||
if path != "" {
|
|
||||||
cookie.Path = path
|
|
||||||
}
|
}
|
||||||
|
cookie := http.Cookie{
|
||||||
cookie.Domain = domain
|
Name: name,
|
||||||
cookie.Secure = secure
|
Value: url.QueryEscape(value),
|
||||||
cookie.HttpOnly = httpOnly
|
MaxAge: maxAge,
|
||||||
|
Path: path,
|
||||||
c.Writer.Header().Add("Set-Cookie", cookie.String())
|
Domain: domain,
|
||||||
|
Secure: secure,
|
||||||
|
HttpOnly: httpOnly,
|
||||||
|
}
|
||||||
|
c.Header("Set-Cookie", cookie.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) GetCookie(name string) (string, error) {
|
func (c *Context) Cookie(name string) (string, error) {
|
||||||
cookie, err := c.Request.Cookie(name)
|
cookie, err := c.Request.Cookie(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -3,3 +3,10 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
func (c *Context) GetCookie(name string) (string, error) {
|
||||||
|
log.Println("GetCookie() method is deprecated. Use Cookie() instead.")
|
||||||
|
return c.Cookie(name)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user