去会话变量? [英] Go session variables?

查看:89
本文介绍了去会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Go语言的新手(Golang),我正在编写一个基于Web的应用程序。我想使用会话变量,如PHP中的种类(从一个页面到下一个页面的变量以及用户会话的唯一变量)。 Go有没有这样的东西?如果不是,我将如何去实施它们自己?或者有什么替代方法?

你可能想看看大猩猩。它具有会议支持,如此处所述。



除此之外或其他可能的其他网络工具包之一,您必须自行推出。



可能的解决方案可能是:




  • 每个用户会话的goroutine将会话变量存储在内存中。
  • 将变量存储在会话cookie中。
  • >
  • 使用数据库来存储用户会话数据。



我会留下每个那些给读者。


I'm new to the Go language (Golang) and I'm writing a web-based application. I'd like to use session variables, like the kind in PHP (variables that are available from one page to the next and unique for a user session). Is there something like that in Go? If not, how would I go about implementing them myself? Or what alternatives methods are there?

解决方案

You probably want to take a look at gorilla. It has session support as documented here.

Other than that or possibly one of the other web toolkits for go you would have to roll your own.

Possible solutions might be:

  • goroutine per user session to store session variables in memory.
  • store your variables in a session cookie.
  • use a database to store user session data.

I'll leave the implementation details of each of those to the reader.

这篇关于去会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆