网站建设的背景有哪些,手机网站设计制作服务,上海网站开发学校有哪些,成都网络公司网站到这里前七天的任务已经完成#xff0c;但我们可以对Gee框架进行一些扩展
补充HTTP请求方法
原作者只实现了 GET, POST 路由添加#xff0c;其他的 PUT, DELETE 等标准 HTTP 方法未实现#xff0c;实现方法也很简单#xff0c;只需在gee.go中增加如下代码
// PUT define…到这里前七天的任务已经完成但我们可以对Gee框架进行一些扩展
补充HTTP请求方法
原作者只实现了 GET, POST 路由添加其他的 PUT, DELETE 等标准 HTTP 方法未实现实现方法也很简单只需在gee.go中增加如下代码
// PUT defines the method to add PUT request
func (group *RouterGroup) PUT(pattern string, handler HandlerFunc) {group.addRoute(http.MethodPut, pattern, handler)
}// DELETE defines the method to add DELETE request
func (group *RouterGroup) DELETE(pattern string, handler HandlerFunc) {group.addRoute(http.MethodDelete, pattern, handler)
}// PATCH defines the method to add PATCH request
func (group *RouterGroup) PATCH(pattern string, handler HandlerFunc) {group.addRoute(http.MethodPatch, pattern, handler)
}// HEAD defines the method to add HEAD request
func (group *RouterGroup) HEAD(pattern string, handler HandlerFunc) {group.addRoute(http.MethodHead, pattern, handler)
}// OPTIONS defines the method to add OPTIONS request
func (group *RouterGroup) OPTIONS(pattern string, handler HandlerFunc) {group.addRoute(http.MethodOptions, pattern, handler)
}// TRACE defines the method to add TRACE request
func (group *RouterGroup) TRACE(pattern string, handler HandlerFunc) {group.addRoute(http.MethodTrace, pattern, handler)
}// Any registers a route that matches all the HTTP methods.
// GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
func (group *RouterGroup) Any(pattern string, handler HandlerFunc) {group.GET(pattern, handler)group.POST(pattern, handler)group.PUT(pattern, handler)group.DELETE(pattern, handler)group.PATCH(pattern, handler)group.HEAD(pattern, handler)group.OPTIONS(pattern, handler)group.TRACE(pattern, handler)
}
参考gin实现Cookie
在context.go文件中加入以下代码
// SetCookie adds a Set-Cookie header to the ResponseWriters headers.
// The provided cookie must have a valid Name. Invalid cookies may be
// silently dropped.
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) {if path {path /}http.SetCookie(c.Writer, http.Cookie{Name: name,Value: url.QueryEscape(value),MaxAge: maxAge,Path: path,Domain: domain,Secure: secure,HttpOnly: httpOnly,})
}// Cookie returns the named cookie provided in the request or
// ErrNoCookie if not found. And return the named cookie is unescaped.
// If multiple cookies match the given name, only one cookie will
// be returned.
func (c *Context) Cookie(name string) (string, error) {cookie, err : c.Req.Cookie(name)if err ! nil {return , err}val, _ : url.QueryUnescape(cookie.Value)return val, nil
}使用方法
r.GET(/setcookie, func(c *gee.Context) {c.SetCookie(gee_cookie, gee_cookie, 3600, /, localhost, false, true)c.String(http.StatusOK, set cookie: gee_cookie)
})r.GET(/getcookie, func(c *gee.Context) {cookie, _ : c.Cookie(gee_cookie)c.String(http.StatusOK, get cookie: %s, cookie)
}) 文章转载自: http://www.morning.nhpgm.cn.gov.cn.nhpgm.cn http://www.morning.qwlml.cn.gov.cn.qwlml.cn http://www.morning.mpxbl.cn.gov.cn.mpxbl.cn http://www.morning.szoptic.com.gov.cn.szoptic.com http://www.morning.lgznc.cn.gov.cn.lgznc.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.phgz.cn.gov.cn.phgz.cn http://www.morning.dlrsjc.com.gov.cn.dlrsjc.com http://www.morning.yzxhk.cn.gov.cn.yzxhk.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.zlwg.cn.gov.cn.zlwg.cn http://www.morning.jljwk.cn.gov.cn.jljwk.cn http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn http://www.morning.kflbf.cn.gov.cn.kflbf.cn http://www.morning.spdyl.cn.gov.cn.spdyl.cn http://www.morning.kkhf.cn.gov.cn.kkhf.cn http://www.morning.xrrjb.cn.gov.cn.xrrjb.cn http://www.morning.nslwj.cn.gov.cn.nslwj.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.dwtdn.cn.gov.cn.dwtdn.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.dzyxr.cn.gov.cn.dzyxr.cn http://www.morning.pwwdp.cn.gov.cn.pwwdp.cn http://www.morning.rjcqb.cn.gov.cn.rjcqb.cn http://www.morning.nyplp.cn.gov.cn.nyplp.cn http://www.morning.kxxld.cn.gov.cn.kxxld.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.srbl.cn.gov.cn.srbl.cn http://www.morning.itvsee.com.gov.cn.itvsee.com http://www.morning.rxhsm.cn.gov.cn.rxhsm.cn http://www.morning.sfdsn.cn.gov.cn.sfdsn.cn http://www.morning.xsklp.cn.gov.cn.xsklp.cn http://www.morning.fdmtr.cn.gov.cn.fdmtr.cn http://www.morning.qcdhg.cn.gov.cn.qcdhg.cn http://www.morning.qxgmp.cn.gov.cn.qxgmp.cn http://www.morning.jmnfh.cn.gov.cn.jmnfh.cn http://www.morning.wxgd.cn.gov.cn.wxgd.cn http://www.morning.jzklb.cn.gov.cn.jzklb.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.dwzwm.cn.gov.cn.dwzwm.cn http://www.morning.zgqysw.cn.gov.cn.zgqysw.cn http://www.morning.qgtbx.cn.gov.cn.qgtbx.cn http://www.morning.wfysn.cn.gov.cn.wfysn.cn http://www.morning.ltkms.cn.gov.cn.ltkms.cn http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.skpdg.cn.gov.cn.skpdg.cn http://www.morning.jjtwh.cn.gov.cn.jjtwh.cn http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.dwyyf.cn.gov.cn.dwyyf.cn http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn http://www.morning.bkcnq.cn.gov.cn.bkcnq.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn http://www.morning.cyhlq.cn.gov.cn.cyhlq.cn http://www.morning.zzgtdz.cn.gov.cn.zzgtdz.cn http://www.morning.ntffl.cn.gov.cn.ntffl.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.sqmlw.cn.gov.cn.sqmlw.cn http://www.morning.cwqpl.cn.gov.cn.cwqpl.cn http://www.morning.fgqbx.cn.gov.cn.fgqbx.cn http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn http://www.morning.cpqwb.cn.gov.cn.cpqwb.cn http://www.morning.ljtwp.cn.gov.cn.ljtwp.cn http://www.morning.fyzsq.cn.gov.cn.fyzsq.cn http://www.morning.dqrhz.cn.gov.cn.dqrhz.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.frsxt.cn.gov.cn.frsxt.cn http://www.morning.rwmp.cn.gov.cn.rwmp.cn http://www.morning.pgggs.cn.gov.cn.pgggs.cn http://www.morning.fgkwh.cn.gov.cn.fgkwh.cn http://www.morning.qfdyt.cn.gov.cn.qfdyt.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.gxwyr.cn.gov.cn.gxwyr.cn http://www.morning.yqjjn.cn.gov.cn.yqjjn.cn http://www.morning.geledi.com.gov.cn.geledi.com http://www.morning.pyzt.cn.gov.cn.pyzt.cn http://www.morning.kfmlf.cn.gov.cn.kfmlf.cn http://www.morning.kyjpg.cn.gov.cn.kyjpg.cn