Beego has a built-in session module and supports four engines, including memory, file, MySQL and redis. You can implement your own engine based on the interface.
beego中使用session相当方便,只要在main入口函数中设置如下:
It's easy to use session in Beego, use following code in your main() function:
beego.SessionOn = true
或者通过配置文件配置如下:
Or use configuration file:
sessionon = true
通过这种方式就可以开启session,如何使用session,请看下面的例子:
The following example shows you how to use session in Beego:
Setting save path or link address of corresponding file, MySQL and redis engines, default is empty, corresponding arguments in configuration file: sessionsavepath
To use cache, you need to initialize a `beego.NewBeeCache` object and set expired time, and enable expired check. Then you can use following methods to achieve other operations:
- Get(name string) interface{}
- Put(name string, value interface{}, expired int) error
We know that map is not thread safe in Go, if you don't know it, this article may be helpful for you: [atomic_maps](http://golang.org/doc/faq#atomic_maps). However, we need a kind of thread safe map in practice, especially when we are using goroutines. Therefore, Beego provides a simple built-in thread safe map implementation.
Your project may have a lot of log outputs, but you don't want to output everything after your application is running on the internet, for example, you want to ignore Trace, Debug and Info level log outputs, you can use following setting:
beego.SetLevel(beego.LevelWarning)
这样的话就不会输出小于这个level的日志,日志的排序如下:
Then Beego will not output log that has lower level of LevelWarning. Here is the list of all log levels, order from lower to higher: