78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package f5
|
|
|
|
import (
|
|
"os"
|
|
//"strings"
|
|
//"q5"
|
|
)
|
|
|
|
const (
|
|
ONLINE_ENV = 0
|
|
TEST_ENV = iota
|
|
DEV_ENV = iota
|
|
)
|
|
|
|
var serverEnv int32
|
|
|
|
func IsTestEnv() bool {
|
|
return serverEnv == TEST_ENV
|
|
}
|
|
|
|
func IsOnlineEnv() bool {
|
|
return serverEnv == ONLINE_ENV
|
|
}
|
|
|
|
func IsDevEnv() bool {
|
|
return serverEnv == DEV_ENV
|
|
}
|
|
|
|
/*
|
|
func ExtractRegisterTimeFromSessionId(sessionId string) int64 {
|
|
tmpStrings := strings.Split(sessionId, "_")
|
|
if len(tmpStrings) < 4 {
|
|
return 0
|
|
}
|
|
return new(q5.XValue).SetString(tmpStrings[1]).GetInt64()
|
|
}
|
|
|
|
func ExtractGameIdFromAccountId(accountId string) int32 {
|
|
tmpStrings := strings.Split(accountId, "_")
|
|
if len(tmpStrings) < 2 {
|
|
return 0
|
|
}
|
|
return new(q5.XValue).SetString(tmpStrings[1]).GetInt32()
|
|
}
|
|
|
|
func ExtractChannelFromAccountId(accountId string) int32 {
|
|
tmpStrings := strings.Split(accountId, "_")
|
|
if len(tmpStrings) < 2 {
|
|
return 0
|
|
}
|
|
return new(q5.XValue).SetString(tmpStrings[0]).GetInt32()
|
|
}
|
|
|
|
func ExtractOpenIdFromAccountId(accountId string) string {
|
|
tmpStrings := strings.Split(accountId, "_")
|
|
if len(tmpStrings) < 3 {
|
|
return ""
|
|
}
|
|
return strings.Join(tmpStrings[2:], "_")
|
|
}
|
|
*/
|
|
func New[T any](cb func(*T)) *T {
|
|
obj := new(T)
|
|
cb(obj)
|
|
return obj
|
|
}
|
|
|
|
func init() {
|
|
switch os.Getenv("SERVER_ENV") {
|
|
case "TEST":
|
|
serverEnv = TEST_ENV
|
|
case "DEBUG":
|
|
serverEnv = DEV_ENV
|
|
default:
|
|
serverEnv = ONLINE_ENV
|
|
}
|
|
}
|