/
ghttp_server_config_session.go
54 lines (45 loc) · 1.38 KB
/
ghttp_server_config_session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017 gf Author(https://github.com/snail007/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/snail007/gf.
package ghttp
import (
"time"
"github.com/snail007/gf/os/gsession"
"github.com/snail007/gf/os/glog"
)
// 设置http server参数 - SessionMaxAge
func (s *Server) SetSessionMaxAge(ttl time.Duration) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
return
}
s.config.SessionMaxAge = ttl
s.sessionManager.SetTTL(ttl)
}
// 设置http server参数 - SessionIdName
func (s *Server) SetSessionIdName(name string) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
return
}
s.config.SessionIdName = name
}
// 设置http server参数 - SessionStorage
func (s *Server) SetSessionStorage(storage gsession.Storage) {
if s.Status() == SERVER_STATUS_RUNNING {
glog.Error(gCHANGE_CONFIG_WHILE_RUNNING_ERROR)
return
}
s.config.SessionStorage = storage
s.sessionManager.SetStorage(storage)
}
// 获取http server参数 - SessionMaxAge
func (s *Server) GetSessionMaxAge() time.Duration {
return s.config.SessionMaxAge
}
// 获取http server参数 - SessionIdName
func (s *Server) GetSessionIdName() string {
return s.config.SessionIdName
}