在使用 GetActiveSession 方法时获取的当期活跃的session用户,一段时间后在测试环境中登录的只有3个人登录,可活跃的session变为3000多,session我保存的是3600秒,不知道怎么解决与定位,session中我存了当前用信息。
球大家帮助解决,求不沉!
session配置
sscfg := &session.ManagerConfig{
CookieName: "gosessionid",
EnableSetCookie: true,
Gclifetime: 3600,
Maxlifetime: 3600,
Secure: false,
SessionIDHashFunc: "sha1",
SessionIDHashKey: "sessionidkey",
CookieLifeTime: 0,
ProviderConfig: "",
}
存session数据
func (self *LogonController) Post() {
defer self.ServeJson()
self.Data["host"] = self.Ctx.Request.Host
userId := self.Ctx.Request.Form.Get("username")
pwd := self.Ctx.Request.Form.Get("pwd")
userBasic :=self.Ctx.Request.Form.Get("userbasic")
log.Oper(userId, "Logon")
sess := self.StartSession()
sess.Set("username", userId)//存userID
sess.Set("userBash64",userBasic)//存userbash64
if self.IsDefaultUser(userId) {
self.Data["json"] = self.validateDefaultUser(userId, pwd)
} else {
self.Data["json"] = self.validateDomainUser(userId, pwd)
}
self.WirteLinkAdd(self.Ctx.Request)
}
取session数据
func(this *ControllerCommon) GetJiraProjectList() string {
userBasic :=this.GetCurSessionUserBasic()
client := &http.Client{}
reqest, _ := http.NewRequest("GET", "http://jira.zte.com.cn/rest/api/2/project/", nil)
reqest.Header.Set("Authorization",userBasic)
reqest.Header.Set("Content-Type","application/json;charset=UTF-8")
response,err := client.Do(reqest)
if err != nil {
log.Error("NewRequest Get jiraprojectList fail :", err.Error())
return ""
}
message, _ := ioutil.ReadAll(response.Body)
return string(message)
}
//获取当前活跃用户数
func(this *ControllerCommon)GetSessionNum() int {
return beego.GlobalSessions.GetActiveSession()
}
#3
更多评论