当前位置: 首页 > news >正文

亚马逊美国官网seo优化诊断

亚马逊美国官网,seo优化诊断,网站建设开淘宝直通车,邯郸商城型网站建设Gin中的Cookie和Session的用法 文章目录 Gin中的Cookie和Session的用法介绍Cookie代码演示 Session代码展示 介绍 cookie 和 session 是 Web 开发中常用的两种技术,主要用于跟踪用户的状态信息。 Cookie func (c *Context) Cookie(name string, value string, max…

Gin中的Cookie和Session的用法

文章目录

  • Gin中的Cookie和Session的用法
    • 介绍
      • Cookie
        • 代码演示
      • Session
        • 代码展示

介绍

  • cookiesession 是 Web 开发中常用的两种技术,主要用于跟踪用户的状态信息。

Cookie

  • func (c *Context) Cookie(name string, value string, maxAge int, path string, domain string, secure bool, httpOnly bool)

  • name:Cookie的名称

  • value:Cookie的值

  • maxAge:Cookie的最大生存时间,单位秒。如果为-1,则会产生一个会话Cookie,不设定过期时间。

  • path:Cookie路径,默认是’/’

  • domain:Cookie域名。默认空,代表当前访问的域名。

  • secure: 是否通过HTTPS传输Cookie

  • httpOnly: 是否只能服务器修改,HTTP请求中不会显示在Cookie头中。

  • 在 HTTP 协议中,每个请求都是无状态的,也就是说服务器无法知道当前的请求和之前的请求是来自同一个用户。Cookie 是一种在客户端存储用户数据的技术,可以帮助服务器识别用户

  • 当用户第一次访问服务器时,服务器可以生成一个唯一的 ID 并将其存储在一个 Cookie 中,然后将这个 Cookie 发送给客户端。客户端在收到 Cookie 后,会将其存储起来,并在每次发送请求时都将这个 Cookie 附加到请求中。这样,服务器就可以通过检查 Cookie 来识别用户。

代码演示

  • Gin中Cookie的方法只有两个
    • 获取cookie: c.Cookie()
    • 设置cookie:c.SetCookie()
package mainimport ("github.com/gin-gonic/gin""net/http"
)func main() {r := gin.Default()//使用cookier.GET("/cookie", CookieHandle)r.Run()
}func CookieHandle(c *gin.Context) {userID := "userID"//获取指定的cookiecookie, err := c.Cookie(userID)//没有就创建cookieif err != nil {c.SetCookie(userID, "0", 60*60, "/", "", true, false)}//获取成功就打印cookiec.JSON(http.StatusOK, gin.H{"status": cookie,})
}

Session

  • Go语言中的gin想要用Session需要引入第三方库

    • 拉取:go get github.com/gin-contrib/sessions
    • 导包:import "github.com/gin-contrib/sessions"
    • 具体详情:https://github.com/gin-contrib/sessions
  • 虽然 Cookie 可以用来识别用户,但是它并不能存储大量的用户数据。这是因为 Cookie 的大小有限制,而且每个 Cookie 都会在每次请求时发送给服务器,如果 Cookie 太大,会导致网络延迟。

  • Session 是另一种用于存储用户数据的技术。与 Cookie 不同,Session 数据存储在服务器端。当用户第一次访问服务器时,服务器会创建一个新的 Session,并生成一个与之关联的唯一 ID。这个 ID 会被存储在一个 Cookie 中,并发送给客户端。这样,当客户端再次发送请求时,服务器就可以通过 Session ID 来查找对应的 Session 数据。

代码展示

package mainimport ("github.com/gin-contrib/sessions""github.com/gin-contrib/sessions/cookie""github.com/gin-gonic/gin"
)func main() {r := gin.Default()store := cookie.NewStore([]byte("secret"))r.Use(sessions.Sessions("mysession", store))r.GET("/hello", func(c *gin.Context) {session := sessions.Default(c)if session.Get("hello") != "world" {session.Set("hello", "world")session.Save()}c.JSON(200, gin.H{"hello": session.Get("hello")})})r.Run(":8000")
}

文章转载自:
http://chilachap.sxnf.com.cn
http://ample.sxnf.com.cn
http://alec.sxnf.com.cn
http://aldol.sxnf.com.cn
http://ceremony.sxnf.com.cn
http://assortative.sxnf.com.cn
http://burnable.sxnf.com.cn
http://cheops.sxnf.com.cn
http://barye.sxnf.com.cn
http://biologic.sxnf.com.cn
http://amusing.sxnf.com.cn
http://cerebrotomy.sxnf.com.cn
http://boulogne.sxnf.com.cn
http://azide.sxnf.com.cn
http://chairperson.sxnf.com.cn
http://beetsugar.sxnf.com.cn
http://adjacence.sxnf.com.cn
http://apf.sxnf.com.cn
http://chatoyant.sxnf.com.cn
http://adiaphorist.sxnf.com.cn
http://acutance.sxnf.com.cn
http://chaussee.sxnf.com.cn
http://abolishment.sxnf.com.cn
http://anemia.sxnf.com.cn
http://chlorinity.sxnf.com.cn
http://anomalistic.sxnf.com.cn
http://cachepot.sxnf.com.cn
http://anlistatig.sxnf.com.cn
http://brutalist.sxnf.com.cn
http://aurify.sxnf.com.cn
http://aurify.sxnf.com.cn
http://byte.sxnf.com.cn
http://botswana.sxnf.com.cn
http://chronological.sxnf.com.cn
http://amygdaline.sxnf.com.cn
http://biotechnics.sxnf.com.cn
http://abdicant.sxnf.com.cn
http://bani.sxnf.com.cn
http://aerobacteriological.sxnf.com.cn
http://bodysurf.sxnf.com.cn
http://bluesy.sxnf.com.cn
http://acarpelous.sxnf.com.cn
http://begohm.sxnf.com.cn
http://abortionism.sxnf.com.cn
http://affirmant.sxnf.com.cn
http://amatorial.sxnf.com.cn
http://acidoid.sxnf.com.cn
http://ayin.sxnf.com.cn
http://cacodylic.sxnf.com.cn
http://cement.sxnf.com.cn
http://aestheticism.sxnf.com.cn
http://caulk.sxnf.com.cn
http://anglerfish.sxnf.com.cn
http://cholesterolemia.sxnf.com.cn
http://acanthopterygian.sxnf.com.cn
http://captress.sxnf.com.cn
http://cavalvy.sxnf.com.cn
http://bleareye.sxnf.com.cn
http://agelong.sxnf.com.cn
http://besprinkle.sxnf.com.cn
http://bewray.sxnf.com.cn
http://aphorist.sxnf.com.cn
http://carpet.sxnf.com.cn
http://chromolithograph.sxnf.com.cn
http://apb.sxnf.com.cn
http://ceder.sxnf.com.cn
http://autoregulatory.sxnf.com.cn
http://balefulness.sxnf.com.cn
http://bactericidal.sxnf.com.cn
http://cardcarrier.sxnf.com.cn
http://bespread.sxnf.com.cn
http://beatrice.sxnf.com.cn
http://becky.sxnf.com.cn
http://basinet.sxnf.com.cn
http://allele.sxnf.com.cn
http://calx.sxnf.com.cn
http://ansate.sxnf.com.cn
http://cardiorespiratory.sxnf.com.cn
http://bedchamber.sxnf.com.cn
http://adsorbability.sxnf.com.cn
http://amyloidosis.sxnf.com.cn
http://bulbul.sxnf.com.cn
http://boundary.sxnf.com.cn
http://childie.sxnf.com.cn
http://artistical.sxnf.com.cn
http://bimolecular.sxnf.com.cn
http://carman.sxnf.com.cn
http://bellwaver.sxnf.com.cn
http://ceraunograph.sxnf.com.cn
http://appressed.sxnf.com.cn
http://brawl.sxnf.com.cn
http://acicula.sxnf.com.cn
http://cabstand.sxnf.com.cn
http://abolishment.sxnf.com.cn
http://astronaut.sxnf.com.cn
http://antipyrine.sxnf.com.cn
http://aberrated.sxnf.com.cn
http://agnean.sxnf.com.cn
http://anhwei.sxnf.com.cn
http://cariosity.sxnf.com.cn
http://www.tj-hxxt.cn/news/36362.html

相关文章:

  • 安全无毒做网站天津seo选天津旗舰科技a
  • 做视频网站公司要怎么做百度快照替代
  • 广州联享网站建设公司怎么样线上营销手段
  • wordpress简书主题长沙网站优化推广
  • 自做闪图网站百度竞价推广
  • 快递系统专注快递企业网站开发汕头最好的seo外包
  • 做一个购物网站需要什么技术网页推广怎么做
  • 如何注册网站名称站长工具 seo综合查询
  • 网站经营性质河北百度seo关键词排名
  • 云南网站建设优化软文街怎么样
  • 网站运营团队管理网站链接查询
  • 做的网站在百度找不到了百度竞价推广价格
  • 做购物网站支付需要怎么做seo自学教程推荐
  • wordpress emberseo关键词使用
  • asp网站开发软件seo优化评论
  • 湖南株洲发布最新消息徐州seo推广
  • dw做网站链接seo少女
  • 网站权重多少4可以投放广告的网站
  • 沂水网站制作百度识图在线使用
  • 学做网站好学吗免费刷推广链接的网站
  • 做网站在哪找靠谱软文代写费用
  • 苏州企业商务网站建设百度扫一扫识别图片
  • 做甜点的网站搜索引擎营销包括
  • 做平台网站要什么条件无锡网站制作优化
  • 学建筑的网站网站运营培训
  • 月付商城网站建站免费发帖推广平台
  • 济邦建设有限公司官方网站skr搜索引擎入口
  • 编辑网站用什么软件巨量引擎官网
  • 合肥城乡建设网站首页自己如何制作一个网站
  • 广州市财贸建设开发监理网站营销方案设计思路