|
|
package test
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"crypto/md5"
|
|
|
"joybuywork/internal/app"
|
|
|
"joybuywork/internal/config"
|
|
|
"joybuywork/internal/consts"
|
|
|
"joybuywork/internal/plugins/jsonm"
|
|
|
"joybuywork/internal/repository/dao"
|
|
|
"joybuywork/internal/repository/model"
|
|
|
"joybuywork/internal/repository/withdefault"
|
|
|
"joybuywork/internal/utils"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"math/rand"
|
|
|
"os"
|
|
|
"os/signal"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"syscall"
|
|
|
"testing"
|
|
|
"time"
|
|
|
"unicode"
|
|
|
|
|
|
"github.com/rs/xid"
|
|
|
"github.com/sony/sonyflake"
|
|
|
"github.com/valyala/fasthttp"
|
|
|
"gits.branchcn.com/backend/microcode/plugins/alert/webhook"
|
|
|
"go.etcd.io/etcd/api/v3/mvccpb"
|
|
|
"go.etcd.io/etcd/client/v3"
|
|
|
)
|
|
|
|
|
|
var key = "/test"
|
|
|
|
|
|
var cli *clientv3.Client
|
|
|
|
|
|
func init() {
|
|
|
cli, _ = clientv3.New(clientv3.Config{
|
|
|
Endpoints: []string{"127.0.0.1:2379"},
|
|
|
DialTimeout: 5 * time.Second,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func TestName(t *testing.T) {
|
|
|
|
|
|
for i := 0; i < 1; i++ {
|
|
|
// 监听配置变化
|
|
|
go func() {
|
|
|
|
|
|
ctx := context.Background()
|
|
|
for {
|
|
|
ch, ok := <-cli.Watch(ctx, key, clientv3.WithPrefix())
|
|
|
if !ok {
|
|
|
t.Logf("监听通道有问题")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if ch.Canceled {
|
|
|
t.Logf("退出")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
t.Logf("Created:%v, Header: %+v, CompactRevision: %d, IsProgressNotify: %v", ch.Created, ch.Header, ch.CompactRevision, ch.IsProgressNotify())
|
|
|
|
|
|
for _, ev := range ch.Events {
|
|
|
switch ev.Type {
|
|
|
case mvccpb.PUT:
|
|
|
fmt.Println(string(ev.Kv.Key), string(ev.Kv.Value))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}()
|
|
|
}
|
|
|
|
|
|
//监听程序退出
|
|
|
ch := make(chan os.Signal, 1)
|
|
|
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL)
|
|
|
|
|
|
select {
|
|
|
case <-ch:
|
|
|
defer close(ch)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func TestName2(t *testing.T) {
|
|
|
|
|
|
ctx, _ := context.Background(), time.Second
|
|
|
|
|
|
cli.Put(ctx, "/test/ddd", xid.New().String())
|
|
|
cli.Put(ctx, "/test/your_key", xid.New().String())
|
|
|
|
|
|
resp, err := cli.Get(ctx, "/test", clientv3.WithPrefix())
|
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
for _, ev := range resp.Kvs {
|
|
|
fmt.Println(string(ev.Key), string(ev.Value))
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
func Test_GG(t *testing.T) {
|
|
|
webhook.NewFeiShu(config.Config.Alert.Scenes[0].Url, config.Config.Alert.Scenes[0].Secret).SendText("123123")
|
|
|
}
|
|
|
|
|
|
type R struct {
|
|
|
Code int32
|
|
|
Msg string
|
|
|
Data ListRes
|
|
|
}
|
|
|
|
|
|
type ListRes struct {
|
|
|
List []*ListOne `json:"list"` //列表数据
|
|
|
Total int64 `json:"total"` //数据总条数
|
|
|
}
|
|
|
|
|
|
type ListOne struct {
|
|
|
Id string `json:"id"` //活动ID
|
|
|
Title string `json:"title"` //活动标题
|
|
|
StartDate string `json:"start_date"` //开始时间,如:2023-05-25 15:18:00
|
|
|
EndDate string `json:"end_date"` //结束时间,如:2023-05-25 15:18:00
|
|
|
Status int32 `json:"status"` //发布状态(1-待发布,2-已发布,3-已下线,4-预发布)
|
|
|
CreatedTime int64 `json:"created_time"` //创建时间时间戳
|
|
|
Langs []*ListOneLang `json:"langs"`
|
|
|
Link string `json:"link"` //活动链接
|
|
|
}
|
|
|
|
|
|
type ListOneLang struct {
|
|
|
LangMark string `json:"lang_mark"` //语言标识
|
|
|
TOffset int32 `json:"t_offset"` //时区
|
|
|
Start int64 `json:"start"` //当前语种的开始时间
|
|
|
End int64 `json:"end"` //当前语种的结束时间
|
|
|
}
|
|
|
|
|
|
func TestOpReq(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
|
var data = map[string]interface{}{
|
|
|
"page": 6,
|
|
|
"page_size": 10,
|
|
|
}
|
|
|
|
|
|
body, _ := json.Marshal(data)
|
|
|
token := Md5String(fmt.Sprintf("%s %s", "283c771ced982154abb4dc56828e169fee034bbc", Md5String(string(body))))
|
|
|
|
|
|
req := fasthttp.AcquireRequest()
|
|
|
resp := fasthttp.AcquireResponse()
|
|
|
defer fasthttp.ReleaseRequest(req)
|
|
|
defer fasthttp.ReleaseResponse(resp)
|
|
|
|
|
|
req.Header.SetMethod(fasthttp.MethodPost)
|
|
|
req.Header.Set(fasthttp.HeaderContentType, "application/json")
|
|
|
req.Header.Set("X-Message-Id", fmt.Sprint(ctx.Value(consts.TraceIdKey)))
|
|
|
req.Header.Set(fasthttp.HeaderAuthorization, fmt.Sprintf("Bearer %s", token))
|
|
|
req.SetRequestURI("https://test-tls2s.allapp.link/manage/campaign/campaign_list?project_id=coeeaf6rdj7ie31dgad0")
|
|
|
req.SetBody(body)
|
|
|
|
|
|
client := &fasthttp.Client{
|
|
|
ReadTimeout: 15 * time.Second,
|
|
|
WriteTimeout: 15 * time.Second,
|
|
|
}
|
|
|
|
|
|
err := client.Do(req, resp)
|
|
|
t.Log(err)
|
|
|
t.Log(resp.StatusCode(), string(resp.Body()))
|
|
|
|
|
|
var res R
|
|
|
err = json.Unmarshal(resp.Body(), &res)
|
|
|
|
|
|
t.Log(len(res.Data.List))
|
|
|
|
|
|
for i := range res.Data.List {
|
|
|
t.Log(i)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
type RewardStoreKV struct {
|
|
|
Key string `json:"key" form:"key"` //键
|
|
|
Value string `json:"value" form:"value"` //值
|
|
|
IsShow int32 `json:"is_show" form:"is_show"` //是否展示(0-否,1-是)
|
|
|
}
|
|
|
|
|
|
type RewardStoreLang struct {
|
|
|
Mark string `json:"mark" form:"mark" validate:"required"` //语言标识
|
|
|
Title string `json:"title" form:"title" validate:"required"` //奖品名称
|
|
|
ImageId string `json:"image_id" form:"image_id" validate:"required"` //奖品图片ID
|
|
|
IsDefault int32 `json:"is_default" form:"is_default" validate:"oneof=0 1"` //是否默认语言
|
|
|
WebUrl string `json:"web_url" form:"web_url"` //Web端的跳转地址
|
|
|
AppParam string `json:"app_param" form:"app_param"` //App端的跳转参数
|
|
|
}
|
|
|
|
|
|
func TestOpRewardReq(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
|
var data = map[string]interface{}{
|
|
|
"receive_type": 1,
|
|
|
"url_id": "1",
|
|
|
"kv_data": []*RewardStoreKV{
|
|
|
{
|
|
|
Key: "1",
|
|
|
Value: "3",
|
|
|
IsShow: 0,
|
|
|
},
|
|
|
},
|
|
|
"langs": []*RewardStoreLang{
|
|
|
{
|
|
|
Mark: "en",
|
|
|
Title: "ddfdf",
|
|
|
ImageId: "208663058222764032",
|
|
|
IsDefault: 1,
|
|
|
WebUrl: "",
|
|
|
AppParam: "",
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
|
|
|
body, _ := json.Marshal(data)
|
|
|
token := Md5String(fmt.Sprintf("%s %s", "283c771ced982154abb4dc56828e169fee034bbc", Md5String(string(body))))
|
|
|
|
|
|
req := fasthttp.AcquireRequest()
|
|
|
resp := fasthttp.AcquireResponse()
|
|
|
defer fasthttp.ReleaseRequest(req)
|
|
|
defer fasthttp.ReleaseResponse(resp)
|
|
|
|
|
|
req.Header.SetMethod(fasthttp.MethodPost)
|
|
|
req.Header.Set(fasthttp.HeaderContentType, "application/json")
|
|
|
req.Header.Set("X-Message-Id", fmt.Sprint(ctx.Value(consts.TraceIdKey)))
|
|
|
req.Header.Set(fasthttp.HeaderAuthorization, fmt.Sprintf("Bearer %s", token))
|
|
|
req.SetRequestURI("https://test-tls2s.allapp.link/manage/campaign/reward_store?project_id=coeeaf6rdj7ie31dgad0")
|
|
|
req.SetBody(body)
|
|
|
|
|
|
client := &fasthttp.Client{
|
|
|
ReadTimeout: 15 * time.Second,
|
|
|
WriteTimeout: 15 * time.Second,
|
|
|
}
|
|
|
|
|
|
err := client.Do(req, resp)
|
|
|
t.Log(err)
|
|
|
t.Log(resp.StatusCode(), string(resp.Body()))
|
|
|
|
|
|
}
|
|
|
|
|
|
func Test343(t *testing.T) {
|
|
|
a := sonyflake.NewSonyflake(sonyflake.Settings{})
|
|
|
id, _ := a.NextID()
|
|
|
|
|
|
id2 := app.SnowFlakeNode.Generate().Int64()
|
|
|
|
|
|
id3 := app.SnowFlake11Node.ID()
|
|
|
id4 := app.SnowFlake11Node.ID()
|
|
|
t.Log(id, id2, id3, id4)
|
|
|
|
|
|
}
|
|
|
|
|
|
// Md5String md5字符串
|
|
|
func Md5String(v string) string {
|
|
|
hash := md5.New()
|
|
|
hash.Write([]byte(v))
|
|
|
b := hash.Sum(nil)
|
|
|
|
|
|
return hex.EncodeToString(b)
|
|
|
}
|
|
|
|
|
|
func Test111(t *testing.T) {
|
|
|
fz := time.FixedZone("GMT", int(6)*3600)
|
|
|
fz8 := time.FixedZone("GMT", int(8)*3600)
|
|
|
|
|
|
t.Log(time.Unix(1733846400, 0).In(fz).Unix())
|
|
|
|
|
|
aa, _ := time.ParseInLocation(time.DateTime, "2024-12-18 14:00:00", fz)
|
|
|
bb, _ := time.ParseInLocation(time.DateTime, "2024-12-18 14:00:00", fz8)
|
|
|
t.Log(aa.Unix(), bb.Unix())
|
|
|
}
|
|
|
|
|
|
func Test23(t *testing.T) {
|
|
|
var a = "/manage/fission/create-group"
|
|
|
var upper bool
|
|
|
b := strings.Map(func(r rune) rune {
|
|
|
if r == '/' || r == '-' {
|
|
|
upper = true
|
|
|
return -1
|
|
|
}
|
|
|
|
|
|
if upper {
|
|
|
upper = false
|
|
|
return unicode.ToUpper(r)
|
|
|
}
|
|
|
|
|
|
return r
|
|
|
}, a)
|
|
|
|
|
|
t.Log(b)
|
|
|
}
|
|
|
|
|
|
type Ads struct {
|
|
|
lc sync.RWMutex
|
|
|
Ad Ad
|
|
|
}
|
|
|
|
|
|
type Ad struct {
|
|
|
Webs []*Web `json:"webs"`
|
|
|
Accounts struct {
|
|
|
Test string `json:"test"`
|
|
|
Prod string `json:"prod"`
|
|
|
} `json:"accounts"`
|
|
|
}
|
|
|
|
|
|
type Web struct {
|
|
|
Host string `json:"host"`
|
|
|
Uris []struct {
|
|
|
Uri string `json:"uri"`
|
|
|
} `json:"uris"`
|
|
|
}
|
|
|
|
|
|
// jr
|
|
|
var ids1 = []int64{143, 374}
|
|
|
var ads1 = &Ads{}
|
|
|
var j1 = "{\"accounts\": {\"test\": \"ca-pub-2821871715805907\",\"prod\": \"ca-pub-2821871715805907\"},\"webs\": [{\"host\": \"https://moads-r.allapp.link\",\"uris\": [{\"uri\": \"/business/helldivers-2-and-dead-island-2-support-studio-toadman-interactive-confirms-layoffs/\"},{\"uri\": \"/business/report-until-dawn-remake-developer-ballistic-moon-is-making-layoffs/\"},{\"uri\": \"/business/creative-uks-latest-fund-offers-up-to-25k-to-north-east-teams/\"},{\"uri\": \"/business/new-steam-tweaks-let-devs-highlight-related-games-and-dlc-on-store-pages/\"},{\"uri\": \"/business/mental-health-in-games-charity-take-this-is-facing-extinction/\"},{\"uri\": \"/finance/yes-network-msg-networks-to-launch-combined-new-york-regional-sports-app/\"},{\"uri\": \"/finance/nvidia-announces-50-billion-stock-buyback/\"},{\"uri\": \"/finance/nvidia-reports-122-revenue-growth-on-surging-demand-for-data-center-chips/\"},{\"uri\": \"/finance/ford-joins-list-of-companies-walking-back-dei-policies/\"},{\"uri\": \"/finance/lego-revenue-jumps-13-in-first-half-of-2024-boosted-by-lego-fortnite-and-diverse-brick-sets/\"},{\"uri\": \"/finance/nordstrom-shares-climb-5-as-earnings-top-estimates-but-retailer-issues-cautious-guidance/\"},{\"uri\": \"/news/civilization-7-interview-firaxis-answers-all-of-our-questions-about-the-anticipated-sequel-gamescom-2024/\"},{\"uri\": \"/news/crimson-desert-is-like-god-of-war-and-dragons-dogma-had-a-baby-gamescom-2024/\"},{\"uri\": \"/news/borderlands-4-announced-with-teaser-trailer-at-opening-night-live-gamescom-2024/\"},{\"uri\": \"/news/indiana-jones-and-the-great-circle-finally-gets-a-release-date-for-xboxand-playstation-gamescom-2024/\"},{\"uri\": \"/news/secret-level-every-video-game-in-the-new-gamescom-trailer/\"},{\"uri\": \"/news/ign-uk-podcast-762-the-best-of-gamescom-2024/\"}]}]}"
|
|
|
|
|
|
// dhg
|
|
|
var ids2 = []int64{361}
|
|
|
var ads2 = &Ads{}
|
|
|
var j2 = "{\"accounts\": {\"test\": \"ca-pub-2821871715805907\",\"prod\": \"ca-pub-2821871715805907\"},\"webs\": [{\"host\": \"https://moads-dh.branchcn.com\",\"uris\": [{\"uri\": \"/post/the-cost-of-temptation/\"},{\"uri\": \"/post/the-temptation-within-a-tale-of-infidelity/\"},{\"uri\": \"/unexpected-encounter/sweet-deceptions-the-story-of-athena-and-dax/\"}]}]}"
|
|
|
|
|
|
func Test2345(t *testing.T) {
|
|
|
err1 := jsonm.Unmarshal([]byte(j1), &ads1.Ad)
|
|
|
err2 := jsonm.Unmarshal([]byte(j2), &ads2.Ad)
|
|
|
t.Log(err1)
|
|
|
t.Log(err2)
|
|
|
}
|
|
|
|
|
|
func Test233445(t *testing.T) {
|
|
|
t.Log(fmt.Sprintf("[%s]的mysql连接使用已经超过设置90%%(%d/%d)", utils.GetIp(), 1, 2))
|
|
|
}
|
|
|
|
|
|
func TestLL(t *testing.T) {
|
|
|
var err error
|
|
|
defer func() {
|
|
|
ll(err)
|
|
|
}()
|
|
|
|
|
|
err = errors.New("test error")
|
|
|
}
|
|
|
|
|
|
func ll(err error) {
|
|
|
var aaa map[string]map[int64]interface{}
|
|
|
|
|
|
_, ok := aaa["dfsdf"][0]
|
|
|
if !ok {
|
|
|
log.Print(123132)
|
|
|
aaa["dfsdf"] = make(map[int64]interface{})
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
func TestFissionUser(t *testing.T) {
|
|
|
for i := 0; i < 50; i++ {
|
|
|
var add = make([]*model.FissionUser, 0, 200)
|
|
|
var add2 = make([]*model.FissionUserStat, 0, 200)
|
|
|
for j := 0; j < 100; j++ {
|
|
|
userId := xid.New().String()
|
|
|
one := withdefault.FissionUser(&model.FissionUser{
|
|
|
HashID: xid.New().String(),
|
|
|
CampaignID: 5186,
|
|
|
SubUserID: userId,
|
|
|
UserMark: userId,
|
|
|
UserType: 2,
|
|
|
Source: 1,
|
|
|
})
|
|
|
|
|
|
add = append(add, one)
|
|
|
|
|
|
add2 = append(add2, withdefault.FissionUserStat(&model.FissionUserStat{
|
|
|
UserID: one.ID,
|
|
|
CampaignID: one.CampaignID,
|
|
|
HelpNum: rand.Int63n(100),
|
|
|
}))
|
|
|
}
|
|
|
dao.FissionUser.SubTable(5186).WithContext(context.Background()).Create(add...)
|
|
|
dao.FissionUserStat.WithContext(context.Background()).Create(add2...)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
type StcMap struct {
|
|
|
A int
|
|
|
B int
|
|
|
}
|
|
|
|
|
|
type G struct {
|
|
|
dataMap map[int]*StcMap
|
|
|
}
|
|
|
|
|
|
func (g *G) name() {
|
|
|
c := g.dataMap[1]
|
|
|
g.add(c)
|
|
|
}
|
|
|
|
|
|
func (g *G) add(c *StcMap) {
|
|
|
c.B++
|
|
|
}
|
|
|
|
|
|
func TestUnoCards(t *testing.T) {
|
|
|
|
|
|
g := &G{
|
|
|
dataMap: make(map[int]*StcMap),
|
|
|
}
|
|
|
|
|
|
g.dataMap[1] = &StcMap{
|
|
|
A: 1,
|
|
|
B: 2,
|
|
|
}
|
|
|
|
|
|
g.name()
|
|
|
|
|
|
t.Log(g.dataMap[1].B)
|
|
|
|
|
|
}
|