mirror of
https://github.com/bit1001/tdl.git
synced 2025-01-07 20:28:11 +08:00
38 lines
587 B
Go
38 lines
587 B
Go
package key
|
|
|
|
import (
|
|
"bytes"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
var keyPool = sync.Pool{
|
|
New: func() interface{} {
|
|
b := &bytes.Buffer{}
|
|
b.Grow(16)
|
|
return b
|
|
},
|
|
}
|
|
|
|
func New(indexes ...string) string {
|
|
buf := keyPool.Get().(*bytes.Buffer)
|
|
buf.WriteString(strings.Join(indexes, ":"))
|
|
|
|
t := buf.String()
|
|
buf.Reset()
|
|
keyPool.Put(buf)
|
|
return t
|
|
}
|
|
|
|
func Session() string {
|
|
return New("session")
|
|
}
|
|
|
|
func State(userID int64) string {
|
|
return New("state", strconv.FormatInt(userID, 10))
|
|
}
|
|
|
|
func StateChannel(userID int64) string {
|
|
return New("chan", strconv.FormatInt(userID, 10))
|
|
}
|