Skip to content

Commit e82c705

Browse files
authored
Merge pull request #137 from devfeel/develop
Version 1.5.4
2 parents 84dcd47 + b49c293 commit e82c705

File tree

9 files changed

+42
-30
lines changed

9 files changed

+42
-30
lines changed

config/configs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ type (
6060
// SessionNode dotweb app's session config
6161
SessionNode struct {
6262
EnabledSession bool `xml:"enabled,attr"` //启用Session
63-
SessionMode string `xml:"mode,attr"` //session模式,目前支持runtime、redis
64-
Timeout int64 `xml:"timeout,attr"` //session超时时间,分为单位
65-
ServerIP string `xml:"serverip,attr"` //远程session serverip
66-
StoreKeyPre string `xml:"storekeypre,attr"` //远程session StoreKeyPre
63+
SessionMode string `xml:"mode,attr"` //session mode,now support runtime、redis
64+
CookieName string `xml:"cookiename,attr"` //custom cookie name which sessionid store, default is dotweb_sessionId
65+
Timeout int64 `xml:"timeout,attr"` //session time-out period, with minute
66+
ServerIP string `xml:"serverip,attr"` //remote session server url
67+
StoreKeyPre string `xml:"storekeypre,attr"` //remote session StoreKeyPre
6768
}
6869

6970
// RouterNode dotweb app's router config

consts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotweb
22

33
//Global define
44
const(
5-
Version = "1.4.9.6"
5+
Version = "1.5.4"
66
)
77

88
//Log define

dotweb.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ func (app *DotWeb) initAppConfig() {
348348
app.OfflineServer.SetOffline(config.Offline.Offline, config.Offline.OfflineText, config.Offline.OfflineUrl)
349349
}
350350

351-
//设置session
352-
if config.Session.EnabledSession {
353-
app.HttpServer.SetEnabledSession(config.Session.EnabledSession)
354-
app.HttpServer.SetSessionConfig(session.NewStoreConfig(config.Session.SessionMode, config.Session.Timeout, config.Session.ServerIP, config.Session.StoreKeyPre))
355-
}
356-
357351
//设置启用详细请求数据统计
358352
if config.Server.EnabledDetailRequestData {
359353
core.GlobalState.EnabledDetailRequestData = config.Server.EnabledDetailRequestData

feature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (f *xFeatureTools) SetSession(httpCtx *HttpContext) {
3434
} else {
3535
httpCtx.sessionID = httpCtx.HttpServer().GetSessionManager().NewSessionID()
3636
cookie := &http.Cookie{
37-
Name: httpCtx.HttpServer().sessionManager.CookieName,
37+
Name: httpCtx.HttpServer().sessionManager.StoreConfig().CookieName,
3838
Value: url.QueryEscape(httpCtx.SessionID()),
3939
Path: "/",
4040
}

logger/logger.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import (
99
)
1010

1111
const (
12-
LogLevel_Debug = "debug"
13-
LogLevel_Info = "info"
14-
LogLevel_Warn = "warn"
15-
LogLevel_Error = "error"
12+
// LogLevelDebug debug log level
13+
LogLevelDebug = "DEBUG"
14+
// LogLevelInfo info log level
15+
LogLevelInfo = "INFO"
16+
// LogLevelWarn warn log level
17+
LogLevelWarn = "WARN"
18+
// LogLevelError error log level
19+
LogLevelError = "ERROR"
1620
)
1721

1822
type AppLog interface {

logger/xlog.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ const (
4141

4242
// Debug debug log with default format
4343
func (l *xLog) Debug(log string, logTarget string) {
44-
l.log(log, logTarget, LogLevel_Debug, false)
44+
l.log(log, logTarget, LogLevelDebug, false)
4545
}
4646

4747
// Print debug log with no format
4848
func (l *xLog) Print(log string, logTarget string) {
49-
l.log(log, logTarget, LogLevel_Debug, true)
49+
l.log(log, logTarget, LogLevelDebug, true)
5050
}
5151

5252
// Info info log with default format
5353
func (l *xLog) Info(log string, logTarget string) {
54-
l.log(log, logTarget, LogLevel_Info, false)
54+
l.log(log, logTarget, LogLevelInfo, false)
5555
}
5656

5757
// Warn warn log with default format
5858
func (l *xLog) Warn(log string, logTarget string) {
59-
l.log(log, logTarget, LogLevel_Warn, false)
59+
l.log(log, logTarget, LogLevelWarn, false)
6060
}
6161

6262
// Error error log with default format
6363
func (l *xLog) Error(log string, logTarget string) {
64-
l.log(log, logTarget, LogLevel_Error, false)
64+
l.log(log, logTarget, LogLevelError, false)
6565
}
6666

6767
// log push log into chan
@@ -120,7 +120,7 @@ func (l *xLog) writeLog(chanLog chanLog, level string) {
120120
}
121121
log := chanLog.Content
122122
if !chanLog.isRaw {
123-
log = fmt.Sprintf("[%s] %s [%s:%v] %s", chanLog.LogLevel, time.Now().Format(defaultFullTimeLayout), chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content)
123+
log = fmt.Sprintf("%s [%s] [%s:%v] %s", time.Now().Format(defaultFullTimeLayout), chanLog.LogLevel, chanLog.logCtx.fileName, chanLog.logCtx.line, chanLog.Content)
124124
}
125125
if l.enabledConsole {
126126
fmt.Println(log)

server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (server *HttpServer) SetSessionConfig(storeConfig *session.StoreConfig) {
206206
server.SessionConfig().SessionMode = storeConfig.StoreName
207207
server.SessionConfig().ServerIP = storeConfig.ServerIP
208208
server.SessionConfig().StoreKeyPre = storeConfig.StoreKeyPre
209+
server.SessionConfig().CookieName = storeConfig.CookieName
209210
logger.Logger().Debug("DotWeb:HttpServer SetSessionConfig ["+jsonutil.GetJsonString(storeConfig)+"]", LogTarget_HttpServer)
210211
}
211212

@@ -216,6 +217,7 @@ func (server *HttpServer) InitSessionManager() {
216217
storeConfig.StoreName = server.SessionConfig().SessionMode
217218
storeConfig.ServerIP = server.SessionConfig().ServerIP
218219
storeConfig.StoreKeyPre = server.SessionConfig().StoreKeyPre
220+
storeConfig.CookieName = server.SessionConfig().CookieName
219221

220222
if server.sessionManager == nil {
221223
//设置Session

session/session.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ type (
3535
StoreConfig struct {
3636
StoreName string
3737
Maxlifetime int64
38+
CookieName string //custom cookie name which sessionid store
3839
ServerIP string //if use redis, connection string, like "redis://:password@10.0.1.11:6379/0"
3940
StoreKeyPre string //if use redis, set custom redis key-pre; default is dotweb:session:
4041
}
4142

4243
SessionManager struct {
4344
store SessionStore
44-
CookieName string `json:"cookieName"`
4545
GCLifetime int64 `json:"gclifetime"`
4646
storeConfig *StoreConfig
4747
}
@@ -94,22 +94,21 @@ func NewStoreConfig(storeName string, maxlifetime int64, serverIp string, storeK
9494

9595
//create new session manager with default config info
9696
func NewDefaultSessionManager(config *StoreConfig) (*SessionManager, error) {
97-
return NewSessionManager(DefaultSessionCookieName, DefaultSessionGCLifeTime, config)
97+
return NewSessionManager(DefaultSessionGCLifeTime, config)
9898
}
9999

100100
//create new seesion manager
101-
func NewSessionManager(cookieName string, gcLifetime int64, config *StoreConfig) (*SessionManager, error) {
101+
func NewSessionManager(gcLifetime int64, config *StoreConfig) (*SessionManager, error) {
102102
if gcLifetime <= 0 {
103103
gcLifetime = DefaultSessionGCLifeTime
104104
}
105-
if cookieName == "" {
106-
cookieName = DefaultSessionCookieName
105+
if config.CookieName == "" {
106+
config.CookieName = DefaultSessionCookieName
107107
}
108108
manager := &SessionManager{
109109
store: GetSessionStore(config),
110110
GCLifetime: gcLifetime,
111111
storeConfig: config,
112-
CookieName: cookieName,
113112
}
114113
//开启GC
115114
go func() {
@@ -118,16 +117,21 @@ func NewSessionManager(cookieName string, gcLifetime int64, config *StoreConfig)
118117
return manager, nil
119118
}
120119

121-
//create new session id with DefaultSessionLength
120+
// NewSessionID create new session id with DefaultSessionLength
122121
func (manager *SessionManager) NewSessionID() string {
123122
val := cryptos.GetRandString(DefaultSessionLength)
124123
return val
125124
}
126125

126+
// StoreConfig return store config
127+
func (manager *SessionManager) StoreConfig() *StoreConfig{
128+
return manager.storeConfig
129+
}
130+
127131
//get session id from client
128132
//default mode is from cookie
129133
func (manager *SessionManager) GetClientSessionID(req *http.Request) (string, error) {
130-
cookie, err := req.Cookie(manager.CookieName)
134+
cookie, err := req.Cookie(manager.storeConfig.CookieName)
131135
if err != nil {
132136
return "", err
133137
}

version.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## dotweb版本记录:
22

3+
#### Version 1.5.4
4+
* New feature: Session.StoreConfig support CookieName, used to set custom cookie name which sessionid store, default is dotweb_sessionId
5+
* Update: Config.SessionNode add CookieName, used to set custom cookie name which sessionid store
6+
* Update: default log format update to "Time [LogLevel] [FileName:Line] Content"
7+
* BugFixed: remove init session which exec on dotweb.initAppConfig
8+
* 2018-08-02 15:00
9+
310
#### Version 1.5.3
411
* New feature: HttpServer add Validator which be called by Context.Validate()
512
* New feature: Context add Validate(interface{}) used to validate data with HttpServer::Validator

0 commit comments

Comments
 (0)