Compare commits

...

19 Commits

Author SHA1 Message Date
ayflying
144e2ffb25 修复配置切片的问题 2025-02-26 16:32:19 +08:00
乔焰阳
0a1c3c436e Create README.md 2025-02-26 16:11:14 +08:00
ayflying
8c6be6f487 make方法增加创建配置文件 2025-02-26 16:09:08 +08:00
ayflying
915d474fea 格式导表兼容冒号 2025-02-26 12:21:18 +08:00
ayflying
0cfaa799f5 时间传入不修改时区 2025-02-25 16:38:35 +08:00
ayflying
36a34891db 时间函数使用utc时间计算,预防切换夏令时bug 2025-02-25 15:19:42 +08:00
ayflying
4862dcd1d8 跟新结构体切片 2025-02-11 14:26:06 +08:00
ayflying
9461ad77ed 更新 2025-02-10 16:05:26 +08:00
ayflying
33c45920e3 防止覆盖老方法 2025-02-10 16:03:44 +08:00
ayflying
2b51cc5f7c 修改自动生成模板 2025-02-10 14:42:02 +08:00
ayflying
167f90b250 更新库 2025-02-05 15:54:14 +08:00
ayflying
5e885af295 上传服务器支持分流s3上传 2025-01-24 12:12:58 +08:00
ayflying
b219123ded 加入 elasticsearch 2025-01-20 18:47:02 +08:00
ayflying
d3062a0240 增加cmd命令 2025-01-16 15:57:20 +08:00
ayflying
f9bdc0f707 修复导表支持更多奇怪格式 2025-01-16 15:26:46 +08:00
ayflying
9df7bd891e 调整s3储存 2025-01-15 18:52:53 +08:00
ayflying
6b0d2359c5 修改阿波罗的回调 2025-01-13 11:39:36 +08:00
ayflying
5b1f4066f3 工具类加入 2025-01-09 14:31:33 +08:00
ayflying
037541abc8 修改阿波罗的接入方式 2024-12-27 11:20:42 +08:00
24 changed files with 1364 additions and 105 deletions

8
README.md Normal file
View File

@@ -0,0 +1,8 @@
go语言工具类
####
进行安装
~~~
go get github.com/ayflying/utility_go
~~~

29
act/act.go Normal file
View File

@@ -0,0 +1,29 @@
package act
import (
"github.com/gogf/gf/v2/os/gtime"
)
type act struct {
}
type Sql struct {
UID uint64 `gorm:"primaryKey;comment:玩家编号"`
ActID int `gorm:"primaryKey;comment:活动编号"`
Action string `gorm:"type:text;comment:活动配置"`
UpdatedAt *gtime.Time `gorm:"index;comment:更新时间"`
}
func New() *act {
return &act{}
}
func (s *act) CreateTable(name string) {
//prefix := g.DB().GetPrefix()
//
//g.DB()
//g.DB().Exec(gctx.New())
}

13
act/act.sql Normal file
View File

@@ -0,0 +1,13 @@
create table shiningu_game_act
(
uid bigint not null comment '玩家编号',
act_id int not null comment '活动编号',
action text null comment '活动配置',
updated_at datetime null comment '更新时间',
primary key (uid, act_id)
)
comment '玩家活动数据' charset = utf8mb4;
create index shiningu_game_act_uid_index
on shiningu_game_act (uid);

19
act/save.go Normal file
View File

@@ -0,0 +1,19 @@
package act
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
// 查询表格时候存在
func (s *act) TableExists(name string) bool {
Prefix := g.DB().GetPrefix()
get, err := g.DB().TableFields(gctx.New(), Prefix+name)
if err != nil {
g.Log().Error(gctx.New(), err)
}
if get != nil {
return true
}
return false
}

View File

@@ -1,6 +1,7 @@
package aycache package aycache
import ( import (
"github.com/ayflying/utility_go/aycache/drive"
"github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gcache"
) )
@@ -24,6 +25,10 @@ func New(_name ...string) gcache.Adapter {
cacheAdapterObj = NewAdapterMemory() cacheAdapterObj = NewAdapterMemory()
case "redis": case "redis":
cacheAdapterObj = NewAdapterRedis() cacheAdapterObj = NewAdapterRedis()
case "file":
cacheAdapterObj = NewAdapterFile("runtime/cache")
case "es":
cacheAdapterObj = drive.NewAdapterElasticsearch([]string{"http://127.0.0.1:9200"})
} }
//var client = gcache.New() //var client = gcache.New()

View File

@@ -0,0 +1,119 @@
package drive
import (
"context"
"github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/os/gcache"
"time"
)
type AdapterElasticsearch struct {
//FilePath string
Addresses []string
}
func (a AdapterElasticsearch) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) SetMap(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) SetIfNotExist(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (ok bool, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) SetIfNotExistFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) SetIfNotExistFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Get(ctx context.Context, key interface{}) (*gvar.Var, error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) GetOrSet(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (result *gvar.Var, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) GetOrSetFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) GetOrSetFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Contains(ctx context.Context, key interface{}) (bool, error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Size(ctx context.Context) (size int, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Data(ctx context.Context) (data map[interface{}]interface{}, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Keys(ctx context.Context) (keys []interface{}, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Values(ctx context.Context) (values []interface{}, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Update(ctx context.Context, key interface{}, value interface{}) (oldValue *gvar.Var, exist bool, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) UpdateExpire(ctx context.Context, key interface{}, duration time.Duration) (oldDuration time.Duration, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) GetExpire(ctx context.Context, key interface{}) (time.Duration, error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Remove(ctx context.Context, keys ...interface{}) (lastValue *gvar.Var, err error) {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Clear(ctx context.Context) error {
//TODO implement me
panic("implement me")
}
func (a AdapterElasticsearch) Close(ctx context.Context) error {
//TODO implement me
panic("implement me")
}
func NewAdapterElasticsearch(addresses []string) gcache.Adapter {
return &AdapterElasticsearch{
Addresses: addresses,
}
}

View File

@@ -4,6 +4,10 @@ import (
"context" "context"
"github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gcache"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/util/gconv"
"path"
"strings"
"time" "time"
) )
@@ -12,8 +16,20 @@ type AdapterFile struct {
} }
func (a AdapterFile) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error { func (a AdapterFile) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error {
//TODO implement me //defer a.handleLruKey(ctx, key)
panic("implement me") //expireTime := a.getInternalExpire(duration)
//a.data.Set(key, memoryDataItem{
// a: value,
// a: expireTime,
//})
//c.eventList.PushBack(&adapterMemoryEvent{
// k: key,
// e: expireTime,
//})
arr := strings.Split(":", gconv.String(key))
fileName := path.Join(arr...)
return gfile.PutBytes(fileName, gconv.Bytes(value))
} }
func (a AdapterFile) SetMap(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error { func (a AdapterFile) SetMap(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error {

View File

@@ -11,7 +11,7 @@ var adapterRedisCache = gcache.New()
func NewAdapterRedis() gcache.Adapter { func NewAdapterRedis() gcache.Adapter {
if adapterRedisClient == nil { if adapterRedisClient == nil {
adapterRedisClient = gcache.NewAdapterRedis(g.Redis("cache")) adapterRedisClient = gcache.NewAdapterRedis(g.Redis("default"))
adapterRedisCache.SetAdapter(adapterRedisClient) adapterRedisCache.SetAdapter(adapterRedisClient)
} }
return adapterRedisCache return adapterRedisCache

118
cmd/make.go Normal file
View File

@@ -0,0 +1,118 @@
package cmd
import (
"context"
"embed"
"fmt"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"io/fs"
)
//go:embed make/*
var ConfigFiles embed.FS
var (
Make = gcmd.Command{
Name: "make",
Usage: "make",
Brief: "创建模块文件",
Arguments: []gcmd.Argument{
{Name: "model", Short: "m", Brief: "模块名"},
{Name: "id", Short: "i", Brief: "活动id"},
{Name: "name", Short: "n", Brief: "服务文件名"},
},
Examples: "make -m act -i 1: 创建活动1的接口与服务文件 \n" +
"make -m logic -n test: 创建test的服务文件 \n" +
"make -m config -n test: 创建配置文件",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
//g.Dump(parser.GetOptAll(), parser.GetArgAll())
//return
var model = parser.GetOpt("model").String()
//var name = parser.GetOpt("n").String()
this := cMake{}
switch model {
case "act":
var id = parser.GetOpt("id").Int()
if id == 0 {
return
}
err = this.Act(id)
case "logic":
var name = parser.GetOpt("name").String()
if name == "" {
return
}
err = this.Logic(name)
case "config":
var name = parser.GetOpt("name").String()
if name == "" {
return
}
err = this.Config(name)
}
return
},
}
)
type cMake struct{}
func (c *cMake) Api() {
}
func (c *cMake) Act(id int) (err error) {
filePath := fmt.Sprintf("api/act/v1/act%v.go", id)
//生成文件不覆盖
if !gfile.Exists(filePath) {
err = gfile.PutContents(filePath, "package v1\n")
}
filePath = fmt.Sprintf("internal/game/act/act%d/act%d.go", id, id)
//生成文件不覆盖
if !gfile.Exists(filePath) {
//fileStr := gfile.GetContents(getFilePath)
get, _ := fs.ReadFile(ConfigFiles, "make/act")
fileStr := string(get)
fileStr = gstr.Replace(fileStr, "{id}", gconv.String(id))
err = gfile.PutContents(filePath, fileStr)
}
return
}
func (c *cMake) Logic(name string) (err error) {
var filePath = fmt.Sprintf("internal/logic/%s/%s.go", name, name)
//生成文件不覆盖
if !gfile.Exists(filePath) {
//fileStr := gfile.GetContents("./make/logic")
get, _ := fs.ReadFile(ConfigFiles, "make/act")
fileStr := string(get)
fileStr = gstr.Replace(fileStr, "{package}", name)
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))
err = gfile.PutContents(filePath, fileStr)
}
return
}
func (c *cMake) Config(name string) (err error) {
var filePath = fmt.Sprintf("utility/config/%s.go", name)
//生成文件不覆盖
if !gfile.Exists(filePath) {
get, _ := fs.ReadFile(ConfigFiles, "make/config")
fileStr := string(get)
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))
fileStr = gstr.Replace(fileStr, "{cfg}", gstr.CaseCamel(name))
fileStr = gstr.Replace(fileStr, "{mod}", gstr.CaseCamelLower(name))
fileStr = gstr.Replace(fileStr, "{file}", name)
err = gfile.PutContents(filePath, fileStr)
}
return
}

39
cmd/make/act Normal file
View File

@@ -0,0 +1,39 @@
package act{id}
import (
"game_server/internal/service"
"github.com/gogf/gf/v2/os/gctx"
)
type sAct{id} struct {
}
func New() *sAct{id} {
return &sAct{id}{}
}
var (
ActId = {id}
ctx = gctx.New()
)
type Data struct {
}
func init() {
}
func (s *sAct{id}) GetData(uid int64) (data *Data) {
get, _ := service.GameAct().Info(uid, ActId)
get.Scan(&data)
if get.IsEmpty() || get.IsNil() || data == nil {
data = &Data{
}
}
return
}
func (s *sAct{id}) SetData(uid int64, data interface{}) {
service.GameAct().Set(uid, ActId, data)
}

51
cmd/make/config Normal file
View File

@@ -0,0 +1,51 @@
package config
import (
"github.com/ayflying/utility_go"
"github.com/gogf/gf/v2/util/gutil"
"sync"
)
type {cfg}Cfg struct {
Id int32 `json:"id" dc:"编号"`
}
type {mod}Mod struct {
once sync.Once
lock sync.Mutex
cfgArr []*{cfg}Cfg
cfgMap map[int32]*{cfg}Cfg
}
var {name} = &{mod}Mod{}
func (c *{mod}Mod) Load(_cfg ...string) {
c.lock.Lock()
defer c.lock.Unlock()
c.cfgArr = make([]*{cfg}Cfg, 0)
data, err := utility_go.Config.GetFile("{file}")
err = data.Scan(&c.cfgArr)
if err != nil {
panic(err)
}
c.cfgMap = make(map[int32]*{cfg}Cfg)
for _, v := range c.cfgArr {
c.cfgMap[v.Id] = v
}
}
func (c *{mod}Mod) List() []*{cfg}Cfg {
var list = make([]*{cfg}Cfg, len(c.cfgArr))
for k, v := range c.cfgArr {
list[k] = c.Get(v.Id)
}
return list
}
func (c *{mod}Mod) Get(id int32) *{cfg}Cfg {
if data, ok := c.cfgMap[id]; ok {
return gutil.Copy(data).(*{cfg}Cfg)
}
return nil
}

25
cmd/make/logic Normal file
View File

@@ -0,0 +1,25 @@
package {package}
import (
"game_server/internal/service"
"github.com/gogf/gf/v2/os/gctx"
)
type s{name} struct {
}
var (
ctx = gctx.New()
)
func New() *s{name} {
return &s{name}{}
}
func init() {
service.Register{name}(New())
}
func (s *s{name}) Info() {
}

124
cmd/update.go Normal file
View File

@@ -0,0 +1,124 @@
package cmd
import (
"context"
"github.com/ayflying/utility_go/s3"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx"
"os"
"time"
)
type serverCfg struct {
Name string `json:"name" dc:"服务名"`
Address string `json:"address" dc:"服务地址"`
Prod bool `json:"prod" dc:"是否生产环境"`
S3 string `json:"s3" dc:"使用哪个对象储存中转"`
}
type UpdateReq struct {
File *ghttp.UploadFile `json:"file" binding:"required" dc:"文件"`
FileUrl string `json:"file_url" dc:"文件地址"`
}
var s3Mod *s3.Mod
var (
Update = gcmd.Command{
Name: "update",
Usage: "update",
Brief: "更新系统",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Info(ctx, "准备上传更新文件")
//加载编辑配置文件
g.Cfg("hack").GetAdapter().(*gcfg.AdapterFile).SetFileName("hack/config.yaml")
getFileName, err := g.Cfg("hack").Get(ctx, "gfcli.build.name")
Filename := getFileName.String()
var list []*serverCfg
serverList := g.Cfg().MustGet(ctx, "server_list")
serverList.Scan(&list)
//如果有p或者prod参数则删除prod字段为true的服务
if parser.GetOpt("a").IsNil() {
var temp []*serverCfg
for _, v := range list {
if v.Prod == false {
temp = append(temp, v)
}
}
list = temp
} else {
g.Dump("升级", parser.GetOpt("a"))
}
g.Dump("需要更新的服务器", list)
//获取上传链接
var url = make(map[string]string)
filename := "linux_amd64/" + Filename
client := g.Client()
client.SetTimeout(time.Minute)
client.SetDiscovery(nil)
//循环服务器,推送更新
for _, v := range list {
address := v.Address
if v.S3 == "" {
v.S3 = "default"
}
//查询当前上传地址是否存在
if _, ok := url[v.S3]; !ok {
url[v.S3], err = UploadS3(v.S3, filename)
if err != nil {
g.Log().Error(ctx, err)
return
}
}
g.Log().Debugf(ctx, "准备同步服务器:%v,url=%v", v.Name, address+"/callback/update")
get, err := client.Post(ctx, address+"/callback/update", &UpdateReq{
FileUrl: url[v.S3],
})
if err != nil {
g.Log().Debugf(ctx, "切换代理进行上传:err=%v", err)
get, err = client.Proxy("http://192.168.50.114:10808").
Post(ctx, address+"/callback/update", &UpdateReq{
FileUrl: url[v.S3],
})
}
if err != nil {
g.Log().Error(ctx, err)
}
defer get.Close()
g.Log().Debugf(ctx, "同步服务器:%v,完成=%v", v.Name, address)
}
return
},
}
)
func UploadS3(typ string, filename string) (res string, err error) {
//updateServerS3Name, _ := g.Config().Get(ctx, "update_server_s3_name")
s3Mod = s3.New(typ)
bucketName := s3Mod.GetCfg().BucketName
obj, err := os.Open(filename)
ff, err := obj.Stat()
_, err = s3Mod.PutObject(obj, filename, bucketName, ff.Size())
if err != nil {
return
}
//上传当前文件
get, err := s3Mod.GetFileUrl(filename, bucketName)
g.Log().Debugf(gctx.New(), "下载地址:%s", get)
res = get.String()
return
}

View File

@@ -3,21 +3,21 @@ package config
import ( import (
"fmt" "fmt"
"github.com/apolloconfig/agollo/v4" "github.com/apolloconfig/agollo/v4"
"github.com/apolloconfig/agollo/v4/env/config" apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
"github.com/apolloconfig/agollo/v4/storage" "github.com/apolloconfig/agollo/v4/storage"
"github.com/gogf/gf/contrib/config/apollo/v2"
"github.com/gogf/gf/v2/container/gvar" "github.com/gogf/gf/v2/container/gvar"
"github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gres" "github.com/gogf/gf/v2/os/gres"
"github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/text/gstr"
"path"
"sync" "sync"
"time"
) )
var ( var (
ApolloCfg *config.AppConfig //ApolloCfg *apolloConfig.AppConfig
ApolloCfg *apollo.Config
ApolloListener []string ApolloListener []string
Item2Obj = map[string]Load{} Item2Obj = map[string]Load{}
) )
@@ -71,57 +71,97 @@ func (c *Cfg) GetUrlFile(name string) (jsonObj *gjson.Json, err error) {
} }
// 获取阿波罗 // 获取阿波罗
//func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error) {
// jsonObj, err = c.GetApolloV2(name, obj)
// return
//
// //c.Lock.Lock()
// //defer c.Lock.Unlock()
// //
// //Item2Obj[name+".json"] = obj
// //var cfg = apolloConfig.AppConfig{
// // AppID: ApolloCfg.AppID,
// // Cluster: ApolloCfg.Cluster,
// // IP: ApolloCfg.IP,
// // NamespaceName: name + ".json",
// // Secret: ApolloCfg.Secret,
// // IsBackupConfig: ApolloCfg.IsBackupConfig,
// // BackupConfigPath: ApolloCfg.BackupConfigPath,
// // SyncServerTimeout: 60,
// // MustStart: true,
// //}
// ////cfg.NamespaceName = name + ".json"
// //
// //client, err := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) {
// // return ApolloCfg, nil
// //})
// //if client == nil {
// // return
// //}
// //var getStr string
// //var getApollo *storage.Config
// //for range 5 {
// // getApollo = client.GetConfig(cfg.NamespaceName)
// // if getApollo != nil {
// // break
// // }
// // time.Sleep(time.Second * 5)
// //}
// //
// //if getApollo != nil {
// // getStr = getApollo.GetValue("content")
// // if getStr != "" {
// // //写入配置
// // gfile.PutContents(path.Join("manifest", "game", name+".json"), getStr)
// // }
// //} else {
// // jsonObj, err = c.GetFile(name)
// //}
// //jsonObj, err = gjson.DecodeToJson(getStr)
// ////首次运行加入监听器
// //if !gstr.InArray(ApolloListener, name) {
// // c2 := &CustomChangeListener{}
// // client.AddChangeListener(c2)
// // ApolloListener = append(ApolloListener, name)
// //}
// //return
//}
func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error) { func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error) {
c.Lock.Lock()
defer c.Lock.Unlock()
Item2Obj[name+".json"] = obj Item2Obj[name+".json"] = obj
var cfg = config.AppConfig{
AppID: ApolloCfg.AppID,
Cluster: ApolloCfg.Cluster,
IP: ApolloCfg.IP,
NamespaceName: name + ".json",
Secret: ApolloCfg.Secret,
IsBackupConfig: ApolloCfg.IsBackupConfig,
BackupConfigPath: ApolloCfg.BackupConfigPath,
SyncServerTimeout: 60,
MustStart: true,
}
//cfg.NamespaceName = name + ".json"
client, err := agollo.StartWithConfig(func() (*config.AppConfig, error) { // 接入阿波罗配置
return ApolloCfg, nil ApolloCfg.NamespaceName = name + ".json"
}) adapter, err := apollo.New(nil, *ApolloCfg)
if client == nil { if err != nil {
return g.Log().Fatalf(nil, `%+v`, err)
}
var getStr string
var getApollo *storage.Config
for range 10 {
getApollo = client.GetConfig(cfg.NamespaceName)
if getApollo != nil {
break
}
time.Sleep(time.Second * 5)
} }
// Change the adapter of default configuration instance.
g.Cfg(name).SetAdapter(adapter)
if getApollo != nil {
getStr = getApollo.GetValue("content")
if getStr != "" {
//写入配置
gfile.PutContents(path.Join("manifest", "game", name+".json"), getStr)
}
} else {
jsonObj, err = c.GetFile(name)
}
jsonObj, err = gjson.DecodeToJson(getStr)
//首次运行加入监听器 //首次运行加入监听器
if !gstr.InArray(ApolloListener, name) { if !gstr.InArray(ApolloListener, name+".json") {
//放置监听器
client, _ := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) {
return &apolloConfig.AppConfig{
AppID: ApolloCfg.AppID,
Cluster: ApolloCfg.Cluster,
NamespaceName: ApolloCfg.NamespaceName,
IP: ApolloCfg.IP,
IsBackupConfig: ApolloCfg.IsBackupConfig,
BackupConfigPath: ApolloCfg.BackupConfigPath,
Secret: ApolloCfg.Secret,
SyncServerTimeout: ApolloCfg.SyncServerTimeout,
MustStart: ApolloCfg.MustStart,
}, nil
})
c2 := &CustomChangeListener{} c2 := &CustomChangeListener{}
client.AddChangeListener(c2) client.AddChangeListener(c2)
ApolloListener = append(ApolloListener, name) ApolloListener = append(ApolloListener, name+".json")
} }
cfg, err := g.Cfg(name).Get(nil, "content")
cfg.Scan(&jsonObj)
return return
} }
@@ -131,14 +171,6 @@ type CustomChangeListener struct {
} }
func (c *CustomChangeListener) OnChange(changeEvent *storage.ChangeEvent) { func (c *CustomChangeListener) OnChange(changeEvent *storage.ChangeEvent) {
//write your code here
fmt.Println(changeEvent.Changes)
//for key, value := range changeEvent.Changes {
// fmt.Println("change key : ", key, ", value :", value)
//}
//fmt.Println(changeEvent.Namespace)
//c.wg.Done()
g.Log().Debugf(nil, "当前Namespace变化了%v", changeEvent.Namespace) g.Log().Debugf(nil, "当前Namespace变化了%v", changeEvent.Namespace)
filename := changeEvent.Namespace filename := changeEvent.Namespace
if obj, ok := Item2Obj[filename]; ok { if obj, ok := Item2Obj[filename]; ok {

View File

@@ -0,0 +1,101 @@
package elasticsearch
import (
"context"
"encoding/json"
"fmt"
"github.com/elastic/go-elasticsearch/v8"
)
var (
es *elasticsearch.TypedClient
)
type elastic struct {
client *elasticsearch.TypedClient
}
func New(name ...string) *elastic {
// ES 配置
cfg := elasticsearch.Config{
Addresses: []string{
"http://ay.cname.com:9200",
},
}
if es == nil {
var err error
es, err = elasticsearch.NewTypedClient(cfg)
if err != nil {
fmt.Printf("elasticsearch.NewTypedClient failed, err:%v\n", err)
return &elastic{}
}
}
return &elastic{
client: es,
}
}
// createIndex 创建索引
func (s *elastic) CreateIndex(name string) {
resp, err := s.client.Indices.
Create(name).
Do(context.Background())
if err != nil {
fmt.Printf("create index failed, err:%v\n", err)
return
}
fmt.Printf("index:%#v\n", resp.Index)
}
// indexDocument 索引文档
func (s *elastic) IndexDocument(name string, key string, data interface{}) {
// 添加文档
resp, err := s.client.Index(name).
Id(key).
Document(data).
Do(context.Background())
if err != nil {
fmt.Printf("indexing document failed, err:%v\n", err)
return
}
fmt.Printf("result:%#v\n", resp.Result)
}
// getDocument 获取文档
func (s *elastic) GetDocument(name string, id string) (res json.RawMessage) {
resp, err := s.client.Get(name, id).
Do(context.Background())
if err != nil {
fmt.Printf("get document by id failed, err:%v\n", err)
return
}
fmt.Printf("fileds:%s\n", resp.Source_)
res = resp.Source_
return
}
// updateDocument 更新文档
func (s *elastic) UpdateDocument(name string, key string, data interface{}) {
resp, err := s.client.Update(name, key).
Doc(data). // 使用结构体变量更新
Do(context.Background())
if err != nil {
fmt.Printf("update document failed, err:%v\n", err)
return
}
fmt.Printf("result:%v\n", resp.Result)
}
// deleteDocument 删除 document
func (s *elastic) DeleteDocument(name string, key string) {
resp, err := s.client.Delete(name, key).
Do(context.Background())
if err != nil {
fmt.Printf("delete document failed, err:%v\n", err)
return
}
fmt.Printf("result:%v\n", resp.Result)
}

View File

@@ -16,6 +16,10 @@ import (
"time" "time"
) )
var (
shadiao = []string{",", ":"}
)
type FileItem struct { type FileItem struct {
Name string `json:"name" dc:"配置文件名"` Name string `json:"name" dc:"配置文件名"`
Filename string `json:"filename" dc:"文件名"` Filename string `json:"filename" dc:"文件名"`
@@ -93,8 +97,7 @@ func (s *Excel) itemsFormat(list []interface{}, Items []string) []interface{} {
for k3, v3 := range v2.(g.Map) { for k3, v3 := range v2.(g.Map) {
if gstr.InArray(Items, k3) { if gstr.InArray(Items, k3) {
if _, ok := v3.(string); ok { if _, ok := v3.(string); ok {
list[k2].(g.Map)[k3] = s.Spilt2Item(v3.(string)) list[k2].(g.Map)[k3] = Spilt2Item(v3.(string))
} else { } else {
g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2) g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2)
} }
@@ -109,7 +112,7 @@ func (s *Excel) itemsMapFormat(list []interface{}, Items []string) []interface{}
for k3, v3 := range v2.(g.Map) { for k3, v3 := range v2.(g.Map) {
if gstr.InArray(Items, k3) { if gstr.InArray(Items, k3) {
if _, ok := v3.(string); ok { if _, ok := v3.(string); ok {
get := s.Spilt2Item(v3.(string)) get := Spilt2Item(v3.(string))
list[k2].(g.Map)[k3] = s.Items2Map(get) list[k2].(g.Map)[k3] = s.Items2Map(get)
} else { } else {
g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2) g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2)
@@ -132,14 +135,16 @@ func (s *Excel) sliceFormat(list []interface{}, Slice map[string]string) []inter
list[k2].(g.Map)[k3] = []string{} list[k2].(g.Map)[k3] = []string{}
continue continue
} }
var parts []string var parts []string
//断言是否成功 //断言是否成功
if get, ok := v3.(string); !ok { if get, ok := v3.(string); !ok {
//g.Log().Errorf(gctx.New(), "当前类型断言失败:%v", v3) //g.Log().Errorf(gctx.New(), "当前类型断言失败:%v", v3)
parts = []string{gconv.String(v3)} parts = []string{gconv.String(v3)}
continue
} else { } else {
for _, v := range shadiao {
get = strings.ReplaceAll(get, v, "|")
}
parts = strings.Split(get, "|") // 分割字符串 parts = strings.Split(get, "|") // 分割字符串
} }

View File

@@ -26,8 +26,17 @@ func Excel2Slice(filePath string, _sheet ...string) [][]string {
} }
// 字符串转道具类型 // 字符串转道具类型
func (s *Excel) Spilt2Item(str string) (result [][]int64) { func Spilt2Item(str string) (result [][]int64) {
for _, v := range shadiao {
str = strings.ReplaceAll(str, v, "|")
//parts = append(parts, strings.Split(str, v)...) // 分割字符串
}
//var parts []string
parts := strings.Split(str, "|") // 分割字符串 parts := strings.Split(str, "|") // 分割字符串
if parts == nil {
parts = []string{str}
}
for i := 0; i < len(parts)-1; i += 2 { for i := 0; i < len(parts)-1; i += 2 {
num1, _ := strconv.ParseInt(parts[i], 10, 64) num1, _ := strconv.ParseInt(parts[i], 10, 64)

30
go.mod
View File

@@ -5,8 +5,10 @@ go 1.23.0
require ( require (
github.com/apolloconfig/agollo/v4 v4.4.0 github.com/apolloconfig/agollo/v4 v4.4.0
github.com/ayflying/excel2json v1.1.2 github.com/ayflying/excel2json v1.1.2
github.com/elastic/go-elasticsearch/v8 v8.17.0
github.com/gogf/gf/contrib/config/apollo/v2 v2.8.3
github.com/gogf/gf/v2 v2.8.3 github.com/gogf/gf/v2 v2.8.3
github.com/minio/minio-go/v7 v7.0.82 github.com/minio/minio-go/v7 v7.0.85
github.com/xuri/excelize/v2 v2.9.0 github.com/xuri/excelize/v2 v2.9.0
) )
@@ -15,38 +17,50 @@ require (
github.com/BurntSushi/toml v1.4.0 // indirect github.com/BurntSushi/toml v1.4.0 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.18.0 // indirect github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect github.com/goccy/go-json v0.10.4 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect github.com/gorilla/websocket v1.5.3 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.17.11 // indirect github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/magiconair/properties v1.8.9 // indirect github.com/magiconair/properties v1.8.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/minio/md5-simd v1.1.2 // indirect github.com/minio/md5-simd v1.1.2 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.4 // indirect github.com/richardlehane/msoleps v1.0.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/xid v1.6.0 // indirect github.com/rs/xid v1.6.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.8.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/crypto v0.30.0 // indirect golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.32.0 // indirect golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect golang.org/x/text v0.21.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )

57
go.sum
View File

@@ -43,6 +43,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/agiledragon/gomonkey/v2 v2.11.0 h1:5oxSgA+tC1xuGsrIorR+sYiziYltmJyEZ9qA25b6l5U=
github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apolloconfig/agollo/v4 v4.4.0 h1:bIIRTEN4f7HgLx97/cNpduEvP9qQ7BkCyDOI2j800VM= github.com/apolloconfig/agollo/v4 v4.4.0 h1:bIIRTEN4f7HgLx97/cNpduEvP9qQ7BkCyDOI2j800VM=
@@ -71,6 +72,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA=
github.com/elastic/elastic-transport-go/v8 v8.6.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
github.com/elastic/go-elasticsearch/v8 v8.17.0 h1:e9cWksE/Fr7urDRmGPGp47Nsp4/mvNOrU8As1l2HQQ0=
github.com/elastic/go-elasticsearch/v8 v8.17.0/go.mod h1:lGMlgKIbYoRvay3xWBeKahAiJOgmFDsjZC39nmO3H64=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -97,9 +102,11 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogf/gf/contrib/config/apollo/v2 v2.8.3 h1:KU51l3uaU7Mxq+FSoLjROyDERUGKCMo4qExxPEgA7KQ=
github.com/gogf/gf/contrib/config/apollo/v2 v2.8.3/go.mod h1:Uo6f/Pr6zVHSbdP2Lj9iToEMuh/TzU/bE2E5SJlquEk=
github.com/gogf/gf/v2 v2.8.3 h1:h9Px3lqJnnH6It0AqHRz4/1hx0JmvaSf1IvUir5x1rA= github.com/gogf/gf/v2 v2.8.3 h1:h9Px3lqJnnH6It0AqHRz4/1hx0JmvaSf1IvUir5x1rA=
github.com/gogf/gf/v2 v2.8.3/go.mod h1:n++xPYGUUMadw6IygLEgGZqc6y6DRLrJKg5kqCrPLWY= github.com/gogf/gf/v2 v2.8.3/go.mod h1:n++xPYGUUMadw6IygLEgGZqc6y6DRLrJKg5kqCrPLWY=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@@ -168,6 +175,7 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@@ -189,6 +197,7 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
@@ -199,14 +208,15 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY=
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -229,8 +239,10 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.82 h1:tWfICLhmp2aFPXL8Tli0XDTHj2VB/fNf0PC1f/i1gRo= github.com/minio/minio-go/v7 v7.0.84 h1:D1HVmAF8JF8Bpi6IU4V9vIEj+8pc+xU88EWMs2yed0E=
github.com/minio/minio-go/v7 v7.0.82/go.mod h1:84gmIilaX4zcvAWWzJ5Z1WI5axN+hAbM5w25xf8xvC0= github.com/minio/minio-go/v7 v7.0.84/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY=
github.com/minio/minio-go/v7 v7.0.85 h1:9psTLS/NTvC3MWoyjhjXpwcKoNbkongaCSF3PNpSuXo=
github.com/minio/minio-go/v7 v7.0.85/go.mod h1:57YXpvc5l3rjPdhqNrDsvVlY0qPI6UTk1bflAe+9doY=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
@@ -238,6 +250,7 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
@@ -247,6 +260,7 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
@@ -268,12 +282,19 @@ github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44=
github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -285,6 +306,7 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0=
github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k= github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k=
@@ -309,14 +331,14 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
@@ -327,8 +349,8 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -402,8 +424,8 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -469,7 +491,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
@@ -647,10 +668,12 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -36,8 +36,18 @@ func (s *Mod) Load() {
} }
// CreateF64CountRank 创建一个排行榜实例 name: [name:赛季] // CreateF64CountRank 创建一个排行榜实例
// 参数:
//
// name: 排行榜的名称,通常代表一个赛季
//
// 返回值:
//
// *F64CountRank: 返回一个指向新创建的F64CountRank实例的指针
func (s *Mod) CreateF64CountRank(name string) *F64CountRank { func (s *Mod) CreateF64CountRank(name string) *F64CountRank {
// 初始化F64CountRank实例的name和updateTs字段
// name字段用于标识排行榜的名称格式为"rank:<name>:score"
// updateTs字段用于标识排行榜的更新时间格式为"rank:<name>:updateTs"
return &F64CountRank{ return &F64CountRank{
name: fmt.Sprintf("rank:%s:score", name), name: fmt.Sprintf("rank:%s:score", name),
updateTs: fmt.Sprintf("rank:%s:updateTs", name), updateTs: fmt.Sprintf("rank:%s:updateTs", name),
@@ -86,51 +96,80 @@ func (r *F64CountRank) IncrScore(id int64, score int64) (curScore float64, err e
return return
} }
// 删除当前排行榜 // todo暂时未使用
func (r *F64CountRank) GetCount() {
count, _ := g.Redis().ZCard(ctx, r.name)
if count > 9999 {
//删除超过9999的数据
g.Redis().ZRemRangeByRank(ctx, r.name, 0, -9999)
}
}
// Delete 删除当前排行榜
// 该方法通过删除Redis中与排行榜相关的键来清除排行榜信息
func (r *F64CountRank) Delete() { func (r *F64CountRank) Delete() {
// 删除排行榜数据键
_, err := g.Redis().Del(ctx, r.name) _, err := g.Redis().Del(ctx, r.name)
if err != nil { if err != nil {
// 如果删除失败,记录错误日志
g.Log().Error(ctx, "排行榜删除失败:%v", err) g.Log().Error(ctx, "排行榜删除失败:%v", err)
} }
// 删除排行榜更新时间键
_, err = g.Redis().Del(ctx, r.updateTs) _, err = g.Redis().Del(ctx, r.updateTs)
if err != nil { if err != nil {
// 如果删除失败,记录错误日志
g.Log().Error(ctx, "排行榜删除失败:%v", err) g.Log().Error(ctx, "排行榜删除失败:%v", err)
} }
} }
// DelScore 删除当前分数 // DelScore 删除当前分数
// //
// @Description: // 该方法从更新时间有序集合和排名有序集合中移除指定的id。
// @receiver r // 这通常用于从排行榜中删除一个条目,同时确保其在更新时间集合中的对应记录也被清除。
// @param id //
// @return err // @Description: 从更新时间和排名集合中移除指定id
// @receiver r 接收者为F64CountRank类型的实例
// @param id 要从集合中移除的条目的ID
// @return err 可能发生的错误如果操作成功err为nil
func (r *F64CountRank) DelScore(id int64) (err error) { func (r *F64CountRank) DelScore(id int64) (err error) {
// 从更新时间集合中移除id
_, err = g.Redis().ZRem(ctx, r.updateTs, id) _, err = g.Redis().ZRem(ctx, r.updateTs, id)
// 从排名集合中移除id
_, err = g.Redis().ZRem(ctx, r.name, id) _, err = g.Redis().ZRem(ctx, r.name, id)
return return
} }
// DelScore 删除当前分数 // DelByRank 根据排名范围删除元素。
// // 该方法使用了Redis的有序集合数据结构通过ZRange和ZRemRangeByRank命令来实现。
// @Description: // 参数start和stop定义了要删除的排名范围从start到stop包括start和stop
// @receiver r // 返回可能的错误。
// @param id
// @return err
func (r *F64CountRank) DelByRank(start int64, stop int64) (err error) { func (r *F64CountRank) DelByRank(start int64, stop int64) (err error) {
// 初始化一个空的int64切片用于存储指定排名范围内的元素。
var members []int64 var members []int64
// 使用Redis的ZRange命令获取指定排名范围内的元素。
// 选项Rev设置为true表示按照分数从高到低的顺序返回元素。
get, err := g.Redis().ZRange(ctx, r.name, start, stop, get, err := g.Redis().ZRange(ctx, r.name, start, stop,
gredis.ZRangeOption{ gredis.ZRangeOption{
Rev: true, Rev: true,
}) })
// 使用Scan方法将获取到的元素扫描到members切片中。
err = get.Scan(&members) err = get.Scan(&members)
// 如果扫描过程中出现错误,直接返回错误。
if err != nil { if err != nil {
return return
} }
// 遍历members切片对于每个元素使用ZRem命令从更新时间集合中删除对应的成员。
for _, member := range members { for _, member := range members {
_, err = g.Redis().ZRem(ctx, r.updateTs, member) _, err = g.Redis().ZRem(ctx, r.updateTs, member)
// 忽略ZRem操作的错误因为即使元素不存在ZRem也不会返回错误。
} }
// 使用ZRemRangeByRank命令从有序集合中删除指定排名范围内的元素。
_, err = g.Redis().ZRemRangeByRank(ctx, r.name, start, stop) _, err = g.Redis().ZRemRangeByRank(ctx, r.name, start, stop)
// 返回可能的错误。
return return
} }
@@ -269,44 +308,85 @@ func (r *F64CountRank) UpdateScore(id int64, score int64) (err error) {
//} //}
// GetRankInfosNotTs 获取0~count跳记录 不根据更新时间来 // GetRankInfosNotTs 获取0~count跳记录 不根据更新时间来
// 该方法使用ZRange命令从Redis中获取指定范围的排名信息不考虑更新时间
// 参数:
//
// offset - 获取记录的起始偏移量
// count - 获取记录的数量
//
// 返回值:
//
// list - 排名信息列表
// err - 错误信息,如果执行过程中遇到错误
func (r *F64CountRank) GetRankInfosNotTs(offset, count int) (list []*Data, err error) { func (r *F64CountRank) GetRankInfosNotTs(offset, count int) (list []*Data, err error) {
// 初始化存储成员ID的切片
var members []int64 var members []int64
// 使用Redis的ZRange命令获取指定范围的成员ID
// 参数Rev设为true以从高分到低分获取成员
get, err := g.Redis().ZRange(ctx, r.name, int64(offset), int64(count), get, err := g.Redis().ZRange(ctx, r.name, int64(offset), int64(count),
gredis.ZRangeOption{ gredis.ZRangeOption{
Rev: true, Rev: true,
}) //.ScanSlice(&members) }) //.ScanSlice(&members)
// 将获取的结果扫描到members切片中
err = get.Scan(&members) err = get.Scan(&members)
// 如果发生错误,记录日志并返回
if err != nil { if err != nil {
//logs.Withf("redis err:%v", err) //logs.Withf("redis err:%v", err)
return return
} }
// 根据获取的成员ID数量初始化排名信息列表
list = make([]*Data, len(members)) list = make([]*Data, len(members))
for i := range members { for i := range members {
// 获取当前成员ID
id := members[i] id := members[i]
//id := pgk.InterfaceToNumber[uint64](members[i]) // 使用成员ID获取排名信息不考虑更新时间
list[i] = r.GetIdRankNotTs(id) list[i] = r.GetIdRankNotTs(id)
} }
// 返回排名信息列表和可能的错误
return return
} }
// 获取指定id的当前排名 // GetIdRankNotTs 获取指定id的当前排名
// 该方法从Redis的有序集合中查询指定id的分数和排名信息不考虑时间戳
// 参数:
//
// id - 需要查询排名的id
//
// 返回值:
//
// rankInfo - 包含id的分数和排名信息的指针如果没有找到则返回nil
func (r *F64CountRank) GetIdRankNotTs(id int64) (rankInfo *Data) { func (r *F64CountRank) GetIdRankNotTs(id int64) (rankInfo *Data) {
// 初始化rankInfo结构体设置id其他字段将通过查询填充
rankInfo = &Data{Id: id} rankInfo = &Data{Id: id}
// 查询有序集合中指定id的分数
score, err := g.Redis().ZScore(ctx, r.name, id) score, err := g.Redis().ZScore(ctx, r.name, id)
if err != nil { if err != nil {
// 如果发生错误直接返回rankInfo为初始化状态Id已设置其他字段为零值
return return
} }
// 将分数转换为int64类型并更新rankInfo
rankInfo.Score = int64(score) rankInfo.Score = int64(score)
// 如果分数为0直接返回表示该id的分数为0没有进一步查询排名的必要
if score == 0 { if score == 0 {
return return
} }
// 查询有序集合中指定id的排名
rank, err := g.Redis().ZRevRank(ctx, r.name, id) rank, err := g.Redis().ZRevRank(ctx, r.name, id)
if err != nil { if err != nil {
// 如果发生错误直接返回rankInfo中仅分数有效排名信息未更新
return return
} }
// 更新rankInfo中的排名信息排名从0开始所以需要加1以符合人类的计数习惯
rankInfo.Rank = int32(rank) + 1 rankInfo.Rank = int32(rank) + 1
// 返回包含完整排名信息的rankInfo指针
return rankInfo return rankInfo
} }

View File

@@ -274,14 +274,14 @@ func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err e
// 原始文件 // 原始文件
var dst = minio.CopyDestOptions{ var dst = minio.CopyDestOptions{
Bucket: dstStr, Bucket: bucketName,
Object: bucketName, Object: dstStr,
} }
// 新文件 // 新文件
var src = minio.CopySrcOptions{ var src = minio.CopySrcOptions{
Bucket: srcStr, Bucket: bucketName,
Object: bucketName, Object: srcStr,
} }
_, err = s.client.CopyObject(ctx, dst, src) _, err = s.client.CopyObject(ctx, dst, src)

81
tools/redis.go Normal file
View File

@@ -0,0 +1,81 @@
package tools
import (
"github.com/gogf/gf/v2/database/gredis"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
var (
Redis *redis
)
type redis struct {
}
func (r *redis) Load() {
g.Log().Debugf(gctx.New(), "初始化工具类")
if Redis == nil {
Redis = &redis{}
}
return
}
func (r *redis) RedisScan(cacheKey string, _key ...string) (keys []string, err error) {
var cursor uint64
key := ""
if len(_key) > 0 {
key = _key[0]
}
for {
var newKeys []string
cursor, newKeys, err = g.Redis(key).Scan(ctx, cursor, gredis.ScanOption{
Match: cacheKey,
Count: 1000,
})
if err != nil {
g.Log().Errorf(ctx, "Scan failed: %v", err)
break
}
keys = append(keys, newKeys...)
if cursor == 0 {
break
}
}
return
}
// redis 批量获取大量数据
func (r *redis) RedisScanV2(cacheKey string, _func func([]string) error, _key ...string) error {
//var keys []string
var err error
var cursor uint64
key := ""
if len(_key) > 0 {
key = _key[0]
}
for {
var newKeys []string
cursor, newKeys, err = g.Redis(key).Scan(ctx, cursor, gredis.ScanOption{
Match: cacheKey,
Count: 1000,
})
if err != nil {
g.Log().Errorf(ctx, "Scan failed: %v", err)
break
}
if len(newKeys) > 0 {
err = _func(newKeys)
}
//这个要放在最后
if cursor == 0 {
break
}
}
return err
}

123
tools/time.go Normal file
View File

@@ -0,0 +1,123 @@
package tools
import (
"github.com/gogf/gf/v2/os/gtime"
"time"
)
type timeMod struct {
}
var Time *timeMod
func (m *timeMod) Load() {
if Tools == nil {
Tools = &tools{}
}
}
// 获取本周的开始时间
func (m *timeMod) StartOfWeek(t time.Time) time.Time {
start := gtime.New().AddDate(0, 0, -int(t.Weekday()-1)).Time
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location())
return start
}
func (m *timeMod) StartOfWeekV2(t time.Time) time.Time {
start := t.AddDate(0, 0, -int(t.Weekday()-1))
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location())
return start
}
func (m *timeMod) EndOfWeek(t time.Time) time.Time {
return m.StartOfWeek(t).AddDate(0, 0, 7).Add(-(time.Second * 1))
}
// 获取指定时间的0点时间戳
func (m *timeMod) GetTimeDayZero(tm time.Time) time.Time {
duration := time.Hour*time.Duration(tm.Hour()) + time.Minute*time.Duration(tm.Minute()) + time.Second*time.Duration(tm.Second())
return tm.Add(-duration)
}
// GetWeekZero 获取指定时间周一零点的时间
func (m *timeMod) GetWeekZero(now time.Time) time.Time {
timeUnix := m.GetTimeDayZero(now)
now = timeUnix
daysSinceMonday := int(now.Weekday() - time.Monday)
if daysSinceMonday < 0 {
daysSinceMonday += 7
}
currentMonday := now.AddDate(0, 0, -daysSinceMonday)
return currentMonday
}
// 计算两个时间间隔了几天
func (m *timeMod) GetDayPass(startTime time.Time, t ...time.Time) int {
// 获取时间的年、月、日
year := startTime.Year()
month := startTime.Month()
day := startTime.Day()
// 构建一天的开始时间
startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.Location())
//如果为空,使用当前时间
endTime := time.Now()
if len(t) > 0 {
endTime = t[0]
}
//计算过去了多少天
dayPass := int(endTime.UTC().Sub(startTime.UTC()).Hours() / 24)
return dayPass
}
// 获取下周一的时间
func (m *timeMod) GetNextWeek(now time.Time) time.Time {
now = m.GetWeekZero(now)
timeUnix := now.UnixMilli() + (86400 * 7 * 1000)
nextMondayMidnight := time.UnixMilli(timeUnix)
return nextMondayMidnight
}
// GetDayZeroTime 获取几天后的0点时间
//
// @Description:
// @param currentTime 开始时间
// @param day 多少天后
// @return time.Time
func (m *timeMod) GetDayZeroTime(currentTime time.Time, day int) time.Time {
// 加上指定天数的时间
threeDaysLater := currentTime.AddDate(0, 0, day)
// 调整时间为0点
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 0, 0, 0, 0, threeDaysLater.Location())
return zeroTime
}
// GetEndTime 获取结束的时间
//
// @Description:
// @receiver m
// @param startTime
// @param _day 多少天以后得实际那,当天时间为空
// @return time.Time
func (m *timeMod) GetEndTime(startTime time.Time, _day ...int) time.Time {
var day = 0
if len(_day) > 0 {
day = _day[0]
}
// 加上指定天数的时间
threeDaysLater := startTime.AddDate(0, 0, day)
// 调整时间为0点
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 23, 59, 59, 0, threeDaysLater.Location())
return zeroTime
}
// GetDailyTimeList 获取一个时间段里面每天开始的时间
func (m *timeMod) GetDailyTimeList(time1 time.Time, time2 time.Time) (timeList []time.Time) {
day := m.GetDayPass(time1, time2)
timeList = make([]time.Time, day+1)
for i := 0; i <= day; i++ {
//PassDay := i - day
timeList[i] = m.GetDayZeroTime(time1, i)
}
return
}

225
tools/tools.go Normal file
View File

@@ -0,0 +1,225 @@
package tools
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
"strconv"
"strings"
"time"
)
var (
ctx = gctx.New()
Tools *tools
)
type Number interface {
int | int64 | int32 | int16 | uint64 | uint32 | uint16 | float32 | float64
}
//type Any interface {
// interface{} | string | int | int64 | int32 | int16 | uint64 | uint32 | uint16 | float32 | float64
//}
type toolsInterface interface {
Load()
}
type tools struct {
}
func init() {
g.Log().Debugf(gctx.New(), "初始化工具类")
names := []toolsInterface{
Tools,
}
for _, v := range names {
v.Load()
}
}
func (m *tools) Load() {
if Tools == nil {
Tools = &tools{}
}
}
// 两个时间相隔多少天,需要考虑时区
func (m *tools) GetDay(t1 *gtime.Time, t2 *gtime.Time) int {
if t2 == nil {
t2 = gtime.New(time.UnixMilli(0))
}
return int(t1.Sub(t2).Hours() / 24)
}
//// 字符串转道具类型
//func (m *tools) Spilt2Item(str string) (result [][]int64) {
// parts := strings.Split(str, "|") // 分割字符串
//
// for i := 0; i < len(parts)-1; i += 2 {
// num1, _ := strconv.ParseInt(parts[i], 10, 64)
// num2, _ := strconv.ParseInt(parts[i+1], 10, 64)
//
// pair := []int64{num1, num2}
// result = append(result, pair)
// }
// return
//}
// 字符串转道具类型
func (m *tools) Spilt2Item(str string) (result [][]int64) {
var shadiao = []string{","}
for _, v := range shadiao {
str = strings.ReplaceAll(str, v, "|")
}
//var parts []string
parts := strings.Split(str, "|") // 分割字符串
if parts == nil {
parts = []string{str}
}
for i := 0; i < len(parts)-1; i += 2 {
num1, _ := strconv.ParseInt(parts[i], 10, 64)
num2, _ := strconv.ParseInt(parts[i+1], 10, 64)
pair := []int64{num1, num2}
result = append(result, pair)
}
return
}
// 切片换道具类型
func (m *tools) Slice2Item(slice []int64) (res [][]int64) {
res = make([][]int64, 0)
for i := 0; i < len(slice)-1; i += 2 {
pair := []int64{slice[i], slice[i+1]}
res = append(res, pair)
}
return res
}
// 道具格式转map
func (m *tools) Items2Map(items [][]int64) (list map[int64]int64) {
list = make(map[int64]int64)
for _, v := range items {
list[v[0]] = v[1]
}
return
}
// RemoveSlice 从切片中移除指定的值。
// 参数:
//
// slice: 待操作的切片。
// value: 需要移除的值。
//
// 返回值:
//
// 移除指定值后的切片。
//
// 该函数通过遍历切片,从后向前检查每个元素,如果找到与指定值相等的元素,则将其从切片中移除。
// 这种从后向前的遍历方法可以避免因移除元素而导致的数组重新排列带来的额外计算。
// RemoveSlice 删除切片中的某个值
func RemoveSlice[t Number](slice []t, value t) []t {
// 从后向前遍历切片
for i := len(slice) - 1; i >= 0; i-- {
// 检查当前元素是否等于需要移除的值
if slice[i] == value {
// 如果相等,移除该元素
// 使用append和切片操作符来实现移除操作将i之前和i之后的元素合并到一起
slice = append(slice[:i], slice[i+1:]...)
}
}
// 返回处理后的切片
return slice
}
// InArray 判断当前切片中是否拥有当前值
// InArray[t Number] 支持的类型
//
// @Description:
// @param value 需要查找的值
// @param array 进行查找的切片
// @return bool 返回是否存在
func InArray[t Number](value t, array []t) bool {
for _, v := range array {
if v == value {
return true
}
}
return false
}
// ExtractPage 根据给定的页码和每页大小,从项目切片中提取指定页的项目。
// 它支持泛型,可以用于任何类型的切片。
// 参数:
//
// items: 项目切片,代表所有待分页的项目。
// page: 指定的页码起始页码为1。
// size: 每页的项目数量。
//
// 返回值:
//
// 返回一个切片,包含指定页的项目。
//
// 如果每页大小为0将默认为1。如果项目切片为空或指定页的项目数量少于每页大小且页码大于0则直接返回整个项目切片。
// ExtractPage [t Any]
//
// @Description:
// @param items
// @param page
// @param size
// @return []t
func ExtractPage[t interface{}](items []t, page int, size int) []t {
// 如果每页大小为0将其默认设置为1。
// 如果每页大小为0将其默认设置为1。
if size == 0 {
size = 1
}
// 如果项目切片为空,直接返回空切片。
if len(items) == 0 {
return []t{}
}
//// 如果项目切片长度小于每页大小并且页码大于0返回整个项目切片。
//if len(items) < size && page > 0 {
// //return items
//}
// 计算起始索引和结束索引。
// 根据页码和每页大小计算起始索引和结束索引。
// 计算起始索引和结束索引。
startIndex := (page - 1) * size
endIndex := startIndex + size
// 如果结束索引超出项目切片长度,调整结束索引为项目切片的长度。
// 如果结束索引超出项目切片的长度,将其调整为项目切片的长度。
if endIndex >= len(items) { // 确保不会超出切片范围
endIndex = len(items)
}
// 如果起始索引超出项目切片长度,返回空切片。
if len(items) < startIndex || len(items) < endIndex {
return []t{}
}
// 根据起始索引和结束索引从项目切片中提取指定页的项目,并返回。
// 返回指定页的项目切片。
return items[startIndex:endIndex]
}
// 这是一个用于反转切片的函数示例
// reverseSlice[T comparable]
//
// @Description:
// @param s
// @return []T
func ReverseSlice[T comparable](s []T) []T {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return s
}