Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karldoenitz/tission
一个基于redis和cache实现的session处理插件
https://github.com/karldoenitz/tission
Last synced: 2 months ago
JSON representation
一个基于redis和cache实现的session处理插件
- Host: GitHub
- URL: https://github.com/karldoenitz/tission
- Owner: karldoenitz
- License: mit
- Created: 2019-07-01T06:31:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T09:48:26.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T01:59:48.072Z (6 months ago)
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Badge](https://img.shields.io/badge/link-Tigo-blue.svg)](https://karldoenitz.github.io/Tigo/)
[![LICENSE](https://img.shields.io/badge/license-tission-blue.svg)](https://github.com/karldoenitz/tission/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/karldoenitz/tission.svg?branch=master)](https://travis-ci.org/karldoenitz/tission)
# tission一个基于redis实现的session处理插件,可内嵌入`Tigo`框架使用。
## 安装
```shell
go get github.com/karldoenitz/tission
```## 使用
将此包引入到`Tigo`项目中,简单配置之后即可使用,Demo如下所示:
```go
package mainimport (
"fmt"
"github.com/karldoenitz/Tigo/TigoWeb"
"github.com/karldoenitz/tission/session/redis"
)type Test struct {
A string
B string
}type FrontHandler struct {
TigoWeb.BaseHandler
}func (frontHandler *FrontHandler) Get() {
param := frontHandler.GetParameter("a").ToString()
t := Test{}
if param == "a" {
frontHandler.GetSession("abc", &t) // 从session中取值
frontHandler.ResponseAsJson(t)
return
}
t.A = param
t.B = "from session"
e := frontHandler.SetSession("abc", t) // 设置session值
if e != nil {
fmt.Println(e.Error())
}
frontHandler.ResponseAsJson(t)
}type Testa struct {
TigoWeb.BaseHandler
}func (t * Testa) Get() {
param := t.GetParameter("a").ToString()
if param == "a" {
tt := Test{}
if e := t.GetSession("abc", &tt); e != nil {
println(e.Error())
}
t.ResponseAsJson(tt)
return
}
}var urlMapping = []TigoWeb.Router{
{"/front", &FrontHandler{}, nil},
{"/tt", &Testa{}, nil},
}func main() {
application := TigoWeb.Application{IPAddress: "0.0.0.0", Port: 8888, UrlRouters: urlMapping}
t := redis.SessionInterface{
IP: "127.0.0.1", // redis地址
Port: "6379", // redis端口
MaxIdle: 10,
Timeout: 100,
Expire: 3600, // 3600s后session过期
}
application.StartSession(&t, "tid")
application.Run()
}
```