Cosmetic changes:
- Deprecating GetCookie()
This commit is contained in:
		
							
								
								
									
										51
									
								
								context.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								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 := http.Cookie{ | ||||||
| 	cookie.MaxAge = maxAge | 		Name:     name, | ||||||
|  | 		Value:    url.QueryEscape(value), | ||||||
| 	cookie.Path = "/" | 		MaxAge:   maxAge, | ||||||
| 	if path != "" { | 		Path:     path, | ||||||
| 		cookie.Path = path | 		Domain:   domain, | ||||||
|  | 		Secure:   secure, | ||||||
|  | 		HttpOnly: httpOnly, | ||||||
|  | 	} | ||||||
|  | 	c.Header("Set-Cookie", cookie.String()) | ||||||
| } | } | ||||||
|  |  | ||||||
| 	cookie.Domain = domain | func (c *Context) Cookie(name string) (string, error) { | ||||||
| 	cookie.Secure = secure |  | ||||||
| 	cookie.HttpOnly = httpOnly |  | ||||||
|  |  | ||||||
| 	c.Writer.Header().Add("Set-Cookie", cookie.String()) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func (c *Context) GetCookie(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) | ||||||
|  | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user