Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2b68a202 | ||
|
|
144e2ffb25 | ||
|
|
0a1c3c436e | ||
|
|
8c6be6f487 | ||
|
|
915d474fea | ||
|
|
0cfaa799f5 | ||
|
|
36a34891db | ||
|
|
4862dcd1d8 | ||
|
|
9461ad77ed | ||
|
|
33c45920e3 | ||
|
|
2b51cc5f7c | ||
|
|
167f90b250 |
8
README.md
Normal file
8
README.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
go语言工具类
|
||||||
|
|
||||||
|
####
|
||||||
|
进行安装
|
||||||
|
~~~
|
||||||
|
go get github.com/ayflying/utility_go
|
||||||
|
~~~
|
||||||
|
|
||||||
@@ -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()
|
||||||
|
|||||||
119
aycache/drive/elasticsearch.go
Normal file
119
aycache/drive/elasticsearch.go
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 {
|
||||||
|
|||||||
61
cmd/make.go
61
cmd/make.go
@@ -2,13 +2,18 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gogf/gf/v2/os/gcmd"
|
"github.com/gogf/gf/v2/os/gcmd"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
"io/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed make/*
|
||||||
|
var ConfigFiles embed.FS
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Make = gcmd.Command{
|
Make = gcmd.Command{
|
||||||
Name: "make",
|
Name: "make",
|
||||||
@@ -19,8 +24,9 @@ var (
|
|||||||
{Name: "id", Short: "i", Brief: "活动id"},
|
{Name: "id", Short: "i", Brief: "活动id"},
|
||||||
{Name: "name", Short: "n", Brief: "服务文件名"},
|
{Name: "name", Short: "n", Brief: "服务文件名"},
|
||||||
},
|
},
|
||||||
Examples: "make -m=act -id=1: 创建活动1的接口与服务文件 \n" +
|
Examples: "make -m act -i 1: 创建活动1的接口与服务文件 \n" +
|
||||||
"make -m=logic -n=test: 创建test的服务文件",
|
"make -m logic -n test: 创建test的服务文件 \n" +
|
||||||
|
"make -m config -n test: 创建配置文件",
|
||||||
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
||||||
|
|
||||||
//g.Dump(parser.GetOptAll(), parser.GetArgAll())
|
//g.Dump(parser.GetOptAll(), parser.GetArgAll())
|
||||||
@@ -41,6 +47,12 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = this.Logic(name)
|
err = this.Logic(name)
|
||||||
|
case "config":
|
||||||
|
var name = parser.GetOpt("name").String()
|
||||||
|
if name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = this.Config(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -56,22 +68,51 @@ func (c *cMake) Api() {
|
|||||||
|
|
||||||
func (c *cMake) Act(id int) (err error) {
|
func (c *cMake) Act(id int) (err error) {
|
||||||
filePath := fmt.Sprintf("api/act/v1/act%v.go", id)
|
filePath := fmt.Sprintf("api/act/v1/act%v.go", id)
|
||||||
err = gfile.PutContents(filePath, "package v1\n")
|
//生成文件不覆盖
|
||||||
|
if !gfile.Exists(filePath) {
|
||||||
|
err = gfile.PutContents(filePath, "package v1\n")
|
||||||
|
}
|
||||||
|
|
||||||
filePath = fmt.Sprintf("internal/game/act/act%d/act%d.go", id, id)
|
filePath = fmt.Sprintf("internal/game/act/act%d/act%d.go", id, id)
|
||||||
fileStr := gfile.GetContents("internal/cmd/make/act")
|
//生成文件不覆盖
|
||||||
fileStr = gstr.Replace(fileStr, "{id}", gconv.String(id))
|
if !gfile.Exists(filePath) {
|
||||||
err = gfile.PutContents(filePath, fileStr)
|
//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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cMake) Logic(name string) (err error) {
|
func (c *cMake) Logic(name string) (err error) {
|
||||||
var filePath = fmt.Sprintf("internal/logic/%s/%s.go", name, name)
|
var filePath = fmt.Sprintf("internal/logic/%s/%s.go", name, name)
|
||||||
fileStr := gfile.GetContents("internal/cmd/make/logic")
|
//生成文件不覆盖
|
||||||
fileStr = gstr.Replace(fileStr, "{package}", name)
|
if !gfile.Exists(filePath) {
|
||||||
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))
|
//fileStr := gfile.GetContents("./make/logic")
|
||||||
|
get, _ := fs.ReadFile(ConfigFiles, "make/logic")
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
err = gfile.PutContents(filePath, fileStr)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package act{id}
|
package act{id}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
v1 "game_server/api/act/v1"
|
|
||||||
"game_server/internal/service"
|
"game_server/internal/service"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
)
|
)
|
||||||
@@ -28,7 +27,7 @@ func init() {
|
|||||||
func (s *sAct{id}) GetData(uid int64) (data *Data) {
|
func (s *sAct{id}) GetData(uid int64) (data *Data) {
|
||||||
get, _ := service.GameAct().Info(uid, ActId)
|
get, _ := service.GameAct().Info(uid, ActId)
|
||||||
get.Scan(&data)
|
get.Scan(&data)
|
||||||
if get.IsEmpty() || data == nil {
|
if get.IsEmpty() || get.IsNil() || data == nil {
|
||||||
data = &Data{
|
data = &Data{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
cmd/make/config
Normal file
51
cmd/make/config
Normal 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
|
||||||
|
}
|
||||||
@@ -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,7 +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)
|
||||||
}
|
}
|
||||||
@@ -108,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)
|
||||||
@@ -131,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, "|") // 分割字符串
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ func Excel2Slice(filePath string, _sheet ...string) [][]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 字符串转道具类型
|
// 字符串转道具类型
|
||||||
func (s *Excel) Spilt2Item(str string) (result [][]int64) {
|
func Spilt2Item(str string) (result [][]int64) {
|
||||||
var shadiao = []string{","}
|
|
||||||
for _, v := range shadiao {
|
for _, v := range shadiao {
|
||||||
str = strings.ReplaceAll(str, v, "|")
|
str = strings.ReplaceAll(str, v, "|")
|
||||||
//parts = append(parts, strings.Split(str, v)...) // 分割字符串
|
//parts = append(parts, strings.Split(str, v)...) // 分割字符串
|
||||||
@@ -39,20 +38,6 @@ func (s *Excel) Spilt2Item(str string) (result [][]int64) {
|
|||||||
parts = []string{str}
|
parts = []string{str}
|
||||||
}
|
}
|
||||||
|
|
||||||
//var parts []string
|
|
||||||
//for _, v := range parts1 {
|
|
||||||
// parts = append(parts, strings.Split(v, ",")...) // 分割字符串
|
|
||||||
//}
|
|
||||||
|
|
||||||
//for _, v := range parts1 {
|
|
||||||
// parts2 := strings.Split(v, ",") // 分割字符串
|
|
||||||
// if parts2 == nil {
|
|
||||||
// parts = append(parts, v)
|
|
||||||
// } else {
|
|
||||||
// parts = append(parts, parts2...)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
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)
|
||||||
num2, _ := strconv.ParseInt(parts[i+1], 10, 64)
|
num2, _ := strconv.ParseInt(parts[i+1], 10, 64)
|
||||||
|
|||||||
12
go.mod
12
go.mod
@@ -5,9 +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/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
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,20 +18,19 @@ require (
|
|||||||
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/elastic/elastic-transport-go/v8 v8.6.0 // indirect
|
||||||
github.com/elastic/go-elasticsearch/v8 v8.17.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/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
|
||||||
@@ -56,8 +56,8 @@ require (
|
|||||||
go.opentelemetry.io/otel/metric v1.28.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.28.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/ini.v1 v1.62.0 // indirect
|
||||||
|
|||||||
30
go.sum
30
go.sum
@@ -102,9 +102,10 @@ 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/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=
|
||||||
@@ -214,8 +215,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
|
|||||||
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=
|
||||||
@@ -238,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=
|
||||||
@@ -328,18 +331,12 @@ 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.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
|
||||||
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
|
||||||
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
|
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.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
|
|
||||||
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
|
||||||
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
|
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.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
|
|
||||||
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
|
||||||
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
|
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=
|
||||||
@@ -352,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=
|
||||||
@@ -427,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=
|
||||||
@@ -494,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=
|
||||||
|
|||||||
108
rank/rank.go
108
rank/rank.go
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,14 +60,13 @@ func (m *timeMod) GetDayPass(startTime time.Time, t ...time.Time) int {
|
|||||||
day := startTime.Day()
|
day := startTime.Day()
|
||||||
// 构建一天的开始时间
|
// 构建一天的开始时间
|
||||||
startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.Location())
|
startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.Location())
|
||||||
|
|
||||||
//如果为空,使用当前时间
|
//如果为空,使用当前时间
|
||||||
endTime := time.Now()
|
endTime := time.Now()
|
||||||
if len(t) > 0 {
|
if len(t) > 0 {
|
||||||
endTime = t[0]
|
endTime = t[0]
|
||||||
}
|
}
|
||||||
//计算过去了多少天
|
//计算过去了多少天
|
||||||
dayPass := int(endTime.Sub(startTime).Hours() / 24)
|
dayPass := int(endTime.UTC().Sub(startTime.UTC()).Hours() / 24)
|
||||||
return dayPass
|
return dayPass
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,32 @@ func (m *tools) GetDay(t1 *gtime.Time, t2 *gtime.Time) int {
|
|||||||
return int(t1.Sub(t2).Hours() / 24)
|
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) {
|
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, "|") // 分割字符串
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user