代码拉取完成,页面将自动刷新
package main
import (
"net/http"
"fmt"
"./odsession"
"log"
)
var i int64 = 0
func readGoSession(w http.ResponseWriter, req *http.Request) {
c, err := req.Cookie(cookieName)
//cookie失效
if err != nil {
fmt.Fprintf(w, "nil")
return
}
s := manager.Session(c.Value)
fmt.Print(s.Load("test"))
fmt.Fprintf(w, c.Value)
}
func expireGoSession(w http.ResponseWriter, req *http.Request) {
c, _ := req.Cookie(cookieName)
s := manager.Session(c.Value)
manager.RemoveSession(s.SessionId(), w)
}
var manager odsession.Manager
const cookieName = "gosessionid"
const maxLifeTime = 1800
func HelloServer1(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w,"hello world")
}
func main() {
p := odsession.NewMemoryProvider()
manager, _ = odsession.NewManager(p, cookieName, maxLifeTime) //半个钟
http.HandleFunc("/test", HelloServer)
http.HandleFunc("/read", readGoSession)
http.HandleFunc("/expire", expireGoSession)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。