Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5148627d2d | |||
| da1e982ab5 | |||
|
|
5a12750f11 | ||
|
|
6139b4f722 |
@@ -2,15 +2,16 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ayflying/utility_go/pkg"
|
"github.com/ayflying/utility_go/pkg"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/net/ghttp"
|
"github.com/gogf/gf/v2/net/ghttp"
|
||||||
"github.com/gogf/gf/v2/os/gcfg"
|
"github.com/gogf/gf/v2/os/gcfg"
|
||||||
"github.com/gogf/gf/v2/os/gcmd"
|
"github.com/gogf/gf/v2/os/gcmd"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type serverCfg struct {
|
type serverCfg struct {
|
||||||
@@ -41,22 +42,6 @@ var (
|
|||||||
getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
|
getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
|
||||||
Filename := getFileName.String()
|
Filename := getFileName.String()
|
||||||
|
|
||||||
////获取架构
|
|
||||||
//getArch, err := g.Cfg("hack").Get(ctx, "gfcli.build.arch")
|
|
||||||
//Arch := getArch.String()
|
|
||||||
//if Arch == "" {
|
|
||||||
// Arch = "amd64"
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
////获取操作系统
|
|
||||||
//getSystem, err := g.Cfg("hack").Get(ctx, "gfcli.build.system")
|
|
||||||
//System := getSystem.String()
|
|
||||||
//
|
|
||||||
//if System == "" {
|
|
||||||
// System = "linux"
|
|
||||||
//}
|
|
||||||
//var systemName = System + "_" + Arch
|
|
||||||
|
|
||||||
//获取版本号
|
//获取版本号
|
||||||
getVersion, err := g.Cfg("hack").Get(ctx, "gfcli.build.version")
|
getVersion, err := g.Cfg("hack").Get(ctx, "gfcli.build.version")
|
||||||
Version := getVersion.String()
|
Version := getVersion.String()
|
||||||
|
|||||||
45
package/gamelog/export.go
Normal file
45
package/gamelog/export.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package gamelog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取日志行
|
||||||
|
func (sdk *SDK) GetLogItem(uid, event string, property map[string]any, timezone string, customEventTime ...time.Time) string {
|
||||||
|
loc := time.Local
|
||||||
|
if _loc := getLocationMapValue(timezone); _loc != nil {
|
||||||
|
loc = _loc
|
||||||
|
}
|
||||||
|
if len(property) == 0 {
|
||||||
|
property = map[string]any{"ts": gtime.Now().Timestamp()}
|
||||||
|
}
|
||||||
|
var et *gtime.Time
|
||||||
|
if len(customEventTime) > 0 {
|
||||||
|
et = gtime.NewFromTime(customEventTime[0])
|
||||||
|
} else {
|
||||||
|
et = gtime.Now()
|
||||||
|
}
|
||||||
|
pstr, err := json.Marshal(property)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal property err: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
item := []any{
|
||||||
|
uid,
|
||||||
|
event,
|
||||||
|
pstr,
|
||||||
|
et.TimestampMilli(),
|
||||||
|
et.In(loc).Format(datetimeFmt),
|
||||||
|
}
|
||||||
|
itemstr, err := json.Marshal(item)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal item err: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return gconv.String(itemstr)
|
||||||
|
}
|
||||||
@@ -18,8 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type sendBody struct {
|
type sendBody struct {
|
||||||
Pid string `json:"pid"`
|
Pid string `json:"pid"`
|
||||||
Data [][]any `json:"data"`
|
Data [][]any `json:"data"`
|
||||||
|
SaveType int `json:"save_type" dc:"0=文件存储, 1=kafka存储"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo 游戏日志对象
|
// todo 游戏日志对象
|
||||||
@@ -41,7 +42,8 @@ type SDKConfig struct {
|
|||||||
RetryN int // 每N次重试
|
RetryN int // 每N次重试
|
||||||
ChanSize int // 信道大小, 默认1000
|
ChanSize int // 信道大小, 默认1000
|
||||||
|
|
||||||
reportN int
|
reportN int
|
||||||
|
SendSaveType int // 发送存储类型, 默认不设置为0代表文件存储, 1代表走kafka可实同步日志
|
||||||
}
|
}
|
||||||
|
|
||||||
type SDK struct {
|
type SDK struct {
|
||||||
@@ -379,8 +381,9 @@ func (sdk *SDK) send(logs []GameLog) {
|
|||||||
}
|
}
|
||||||
// json化
|
// json化
|
||||||
sbody := sendBody{
|
sbody := sendBody{
|
||||||
Pid: sdk.sdkConfig.Pid,
|
Pid: sdk.sdkConfig.Pid,
|
||||||
Data: data,
|
Data: data,
|
||||||
|
SaveType: sdk.sdkConfig.SendSaveType,
|
||||||
}
|
}
|
||||||
jsonBody, err := json.Marshal(sbody)
|
jsonBody, err := json.Marshal(sbody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ func TestGamelog(t *testing.T) {
|
|||||||
FlushInterval: 5, // 上报间隔
|
FlushInterval: 5, // 上报间隔
|
||||||
DiskBakPath: "gamelog", // 本地磁盘备份, 用于意外情况下临时保存日志, 请确保该目录持久化(容器内要挂载). 每次启动时或每N次上报时加载到失败队列
|
DiskBakPath: "gamelog", // 本地磁盘备份, 用于意外情况下临时保存日志, 请确保该目录持久化(容器内要挂载). 每次启动时或每N次上报时加载到失败队列
|
||||||
// 可填
|
// 可填
|
||||||
RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据
|
RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据
|
||||||
ChanSize: 500, // 默认1000, 信道size
|
ChanSize: 500, // 默认1000, 信道size
|
||||||
|
SendSaveType: 1, // 发送存储类型, 默认不设置为0代表文件存储, 1代表走kafka可实同步日志
|
||||||
})
|
})
|
||||||
|
|
||||||
// 随机测试事件和属性
|
// 随机测试事件和属性
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
type timeMod struct {
|
type timeMod struct {
|
||||||
@@ -128,3 +129,26 @@ func (m *timeMod) ExcelTime2Time(excelTime string) time.Time {
|
|||||||
timeNew, _ := time.ParseInLocation(layout, excelTime, time.Local)
|
timeNew, _ := time.ParseInLocation(layout, excelTime, time.Local)
|
||||||
return timeNew
|
return timeNew
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 指定时刻刷新
|
||||||
|
// 判断当前是否可领取
|
||||||
|
// createdTime 刷新时刻
|
||||||
|
// lastRwdTime 上次领取时间
|
||||||
|
// now 当前时间
|
||||||
|
func (m *timeMod) CheckIsBeRwd(createdTime, lastRwdTime time.Time, _now ...time.Time) bool {
|
||||||
|
now := time.Now()
|
||||||
|
if len(_now) > 0 {
|
||||||
|
now = _now[0]
|
||||||
|
}
|
||||||
|
//今天的刷新时间
|
||||||
|
refreshToday := time.Date(now.Year(), now.Month(), now.Day(),
|
||||||
|
createdTime.Hour(), createdTime.Minute(), createdTime.Second(),
|
||||||
|
0, createdTime.Location())
|
||||||
|
// 如果今天还没到刷新时间,则刷新时间应是昨天
|
||||||
|
if now.Before(refreshToday) {
|
||||||
|
refreshToday = refreshToday.AddDate(0, 0, -1)
|
||||||
|
}
|
||||||
|
// 判断上次领取时间是否在刷新时间之前
|
||||||
|
// 如果是,则说明还没领过,可以领取
|
||||||
|
return lastRwdTime.Before(refreshToday)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user