Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"compare.go",
"model.go",
"parse_log.go",
"stat.go",
],
importpath = "go-common/app/job/main/passport-game-data/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,33 @@
package model
// CompareRes the result of comparing aso account between local and cloud.
type CompareRes struct {
Flags uint8 `json:"flag"`
FlagsDesc string `json:"flags_desc"`
Seq int64 `json:"seq"`
Local *OriginAsoAccount `json:"local"`
LocalEncrypted *AsoAccount `json:"local_encrypted"`
Cloud *AsoAccount `json:"cloud"`
}
// DiffParseResp diff parse resp.
type DiffParseResp struct {
Total int `json:"total"`
SeqAndPercents []*SeqCountAndPercent `json:"seq_and_percents"`
CountAndPercents []*CountAndPercent `json:"count_and_percents"`
CompareResList []*CompareRes `json:"compare_res_list"`
}
// CountAndPercent count and percent.
type CountAndPercent struct {
DiffType string `json:"diff_type"`
Count int `json:"count"`
Percent string `json:"percent"`
}
// SeqCountAndPercent process goroutine seq count and percent.
type SeqCountAndPercent struct {
Seq int64 `json:"seq"`
Count int `json:"count"`
Percent string `json:"percent"`
}

View File

@@ -0,0 +1,85 @@
package model
import (
"crypto/md5"
"encoding/hex"
"time"
)
const (
_cloudSalt = "bi_clould_tencent_01"
)
// AsoAccount aso account.
type AsoAccount struct {
Mid int64 `json:"mid"`
UserID string `json:"userid"`
Uname string `json:"uname"`
Pwd string `json:"pwd"`
Salt string `json:"salt"`
Email string `json:"email"`
Tel string `json:"tel"`
CountryID int64 `json:"country_id"`
MobileVerified int8 `json:"mobile_verified"`
Isleak int8 `json:"isleak"`
Ctime time.Time `json:"ctime"`
Mtime time.Time `json:"mtime"`
}
// Equals check equals.
func (a *AsoAccount) Equals(b *AsoAccount) bool {
if b == nil {
return false
}
return a.Mid == b.Mid && a.UserID == b.UserID && a.Uname == b.Uname && a.Pwd == b.Pwd &&
a.Salt == b.Salt && a.Email == b.Email && a.Tel == b.Tel && a.CountryID == b.CountryID &&
a.MobileVerified == b.MobileVerified && a.Isleak == b.Isleak
}
// OriginAsoAccount origin aso account.
type OriginAsoAccount struct {
Mid int64 `json:"mid"`
UserID string `json:"userid"`
Uname string `json:"uname"`
Pwd string `json:"pwd"`
Salt string `json:"salt"`
Email string `json:"email"`
Tel string `json:"tel"`
CountryID int64 `json:"country_id"`
MobileVerified int8 `json:"mobile_verified"`
Isleak int8 `json:"isleak"`
Mtime time.Time `json:"modify_time"`
}
// Default doHash aso account, including the followings fields: userid, uname, pwd, email, tel.
func Default(a *OriginAsoAccount) *AsoAccount {
return &AsoAccount{
Mid: a.Mid,
UserID: a.UserID,
Uname: a.Uname,
Pwd: doHash(a.Pwd, _cloudSalt),
Salt: a.Salt,
Email: doHash(a.Email, _cloudSalt),
Tel: doHash(a.Tel, _cloudSalt),
CountryID: a.CountryID,
MobileVerified: a.MobileVerified,
Isleak: a.Isleak,
Mtime: a.Mtime,
}
}
// DefaultHash hash a plain text using default salt.
func DefaultHash(plaintext string) string {
return doHash(plaintext, _cloudSalt)
}
func doHash(plaintext, salt string) string {
if plaintext == "" {
return ""
}
hash := md5.New()
hash.Write([]byte(plaintext))
hash.Write([]byte(salt))
md := hash.Sum(nil)
return hex.EncodeToString(md)
}

View File

@@ -0,0 +1,6 @@
package model
// Log log.
type Log struct {
Log string `json:"log"`
}

View File

@@ -0,0 +1,51 @@
package model
import (
"fmt"
"time"
)
type ProcStat struct {
Cloud2Local *CompareProcStat `json:"cloud_2_local"`
Local2Cloud *CompareProcStat `json:"local_2_cloud"`
}
// CompareProcStat status of compare proc.
type CompareProcStat struct {
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
StepDuration JsonDuration `json:"step_duration"`
LoopDuration JsonDuration `json:"loop_duration"`
DelayDuration JsonDuration `json:"delay_duration"`
BatchSize int `json:"batch_size"`
BatchMissRetryCount int `json:"batch_miss_retry_count"`
Debug bool `json:"debug"`
Fix bool `json:"fix"`
CurrentRangeStart JSONTime `json:"current_range_start"`
CurrentRangeEnd JSONTime `json:"current_range_end"`
CurrentRangeRecordsCount int `json:"current_range_records_count"`
TotalRangeRecordsCount int `json:"total_range_records_count"`
DiffCount int `json:"diff_count"`
Sleeping bool `json:"sleeping"`
SleepFrom string `json:"sleep_from,omitempty"`
SleepSeconds int64 `json:"sleep_seconds,omitempty"`
SleepRemainSeconds int64 `json:"sleep_remain_seconds,omitempty"`
}
type JSONTime time.Time
func (t JSONTime) MarshalJSON() ([]byte, error) {
s := fmt.Sprintf(`"%s"`, time.Time(t).Format("2006-01-02 15:04:05"))
return []byte(s), nil
}
type JsonDuration time.Duration
func (t JsonDuration) MarshalJSON() ([]byte, error) {
s := fmt.Sprintf(`"%v"`, time.Duration(t))
return []byte(s), nil
}