1
This commit is contained in:
parent
2e36e759a9
commit
258d9212ed
@ -1,23 +1,14 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"f5"
|
"f5"
|
||||||
"fmt"
|
|
||||||
"main/constant"
|
"main/constant"
|
||||||
"math/rand"
|
|
||||||
"mt"
|
"mt"
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type app struct {
|
type app struct {
|
||||||
initCb func()
|
initCb func()
|
||||||
unInitCb func()
|
unInitCb func()
|
||||||
sessionLock sync.Mutex
|
|
||||||
sessionHash map[string]string
|
|
||||||
accountIdHash map[string]string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) GetPkgName() string {
|
func (this *app) GetPkgName() string {
|
||||||
@ -37,8 +28,6 @@ func (this *app) Run(initCb func(), unInitCb func()) {
|
|||||||
func (this *app) Init() {
|
func (this *app) Init() {
|
||||||
f5.LoadMetaTable(mt.Table)
|
f5.LoadMetaTable(mt.Table)
|
||||||
this.registerDataSources()
|
this.registerDataSources()
|
||||||
this.sessionHash = make(map[string]string)
|
|
||||||
this.accountIdHash = make(map[string]string)
|
|
||||||
this.initCb()
|
this.initCb()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,45 +48,3 @@ func (this *app) registerDataSources() {
|
|||||||
mt.Table.MailDb.GetById(0).GetDatabase(),
|
mt.Table.MailDb.GetById(0).GetDatabase(),
|
||||||
30)
|
30)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *app) AddSession(accountId string) string {
|
|
||||||
this.sessionLock.Lock()
|
|
||||||
defer this.sessionLock.Unlock()
|
|
||||||
uuid := f5.GetApp().NewUuid()
|
|
||||||
str := fmt.Sprintf("%s%d%s%d", accountId, uuid, randStringBytes(12), time.Now().Unix())
|
|
||||||
md5New := md5.New()
|
|
||||||
strByte := []byte(str)
|
|
||||||
md5New.Write(strByte)
|
|
||||||
md5String := hex.EncodeToString(md5New.Sum(nil))
|
|
||||||
token := accountId + "|" + md5String
|
|
||||||
this.sessionHash[accountId] = token
|
|
||||||
return token
|
|
||||||
}
|
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
||||||
|
|
||||||
func randStringBytes(n int) string {
|
|
||||||
b := make([]byte, n)
|
|
||||||
for i := range b {
|
|
||||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *app) GetSessionAccountId(accountId string) string {
|
|
||||||
this.sessionLock.Lock()
|
|
||||||
defer this.sessionLock.Unlock()
|
|
||||||
if session, ok := this.sessionHash[accountId]; ok {
|
|
||||||
return session
|
|
||||||
} else {
|
|
||||||
return "nil"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *app) RemoveSession(accountId string) {
|
|
||||||
this.sessionLock.Lock()
|
|
||||||
defer this.sessionLock.Unlock()
|
|
||||||
if _, ok := this.sessionHash[accountId]; ok {
|
|
||||||
delete(this.sessionHash, accountId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,9 +2,6 @@ package common
|
|||||||
|
|
||||||
type App interface {
|
type App interface {
|
||||||
Run(func(), func())
|
Run(func(), func())
|
||||||
AddSession(accountId string) string
|
|
||||||
GetSessionAccountId(accountId string) string
|
|
||||||
RemoveSession(accountId string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Player interface {
|
type Player interface {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user