helper

package
v0.0.0-...-8d4f09a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const ImgBindata = "" /* 90820-byte string literal not displayed */
View Source
const Json = "{\"key\": \"value\"}"

Variables

View Source
var AreaCode = []string{
	"11",
	"12",
	"13",
	"14",
	"15",
	"21",
	"22",
	"23",
	"31",
	"32",
	"33",
	"34",
	"35",
	"36",
	"37",
	"41",
	"42",
	"43",
	"44",
	"45",
	"46",
	"50",
	"51",
	"52",
	"53",
	"54",
	"61",
	"62",
	"63",
	"64",
	"65",
	"71",
	"81",
	"82",
	"91",
}
View Source
var AreaCodeMap = map[string]string{
	"11": "北京",
	"12": "天津",
	"13": "河北",
	"14": "山西",
	"15": "内蒙古",
	"21": "辽宁",
	"22": "吉林",
	"23": "黑龙江",
	"31": "上海",
	"32": "江苏",
	"33": "浙江",
	"34": "安徽",
	"35": "福建",
	"36": "江西",
	"37": "山东",
	"41": "河南",
	"42": "湖北",
	"43": "湖南",
	"44": "广东",
	"45": "广西",
	"46": "海南",
	"50": "重庆",
	"51": "四川",
	"52": "贵州",
	"53": "云南",
	"54": "西藏",
	"61": "陕西",
	"62": "甘肃",
	"63": "青海",
	"64": "宁夏",
	"65": "新疆",
	"71": "台湾",
	"81": "香港",
	"82": "澳门",
	"91": "国外",
}
View Source
var AvailableCardTypes = map[string]CardProperties{
	"amex": {
		LongName: "American Express",
		Prefix:   []string{"37", "34"},
		PanSize:  15,
		CvvSize:  4,
	},
	"visa": {
		LongName: "Visa",
		Prefix:   []string{"4"},
		PanSize:  16,
		CvvSize:  3,
	},
	"mc": {
		LongName: "Mastercard",
		Prefix:   []string{"51", "52", "53", "54", "55"},
		PanSize:  16,
		CvvSize:  3,
	},
	"dci": {
		LongName: "Diners Club International",
		Prefix:   []string{"36", "38"},
		PanSize:  16,
		CvvSize:  3,
	},
	"jcb": {
		LongName: "Japan Credit Bureau",
		Prefix:   []string{"35"},
		PanSize:  16,
		CvvSize:  3,
	},
	"discover": {
		LongName: "Discover",
		Prefix:   []string{"6011", "65"},
		PanSize:  16,
		CvvSize:  3,
	},
}
View Source
var ValCodeArr = []string{
	"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2",
}
View Source
var Wi = []int{
	7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2,
}

Functions

func AddMd5

func AddMd5(path, salt string)

func AddPad

func AddPad(str string, field domain.DefField) string

func Base64

func Base64(str string) (ret string)

func ChangePrecision

func ChangePrecision(flt float64, precision int) float64

func ConvertForSql

func ConvertForSql(str string) (ret string)

func ConvertTmFormat

func ConvertTmFormat(field *domain.DefField)

func ConvertYamlStringToMapFormat

func ConvertYamlStringToMapFormat(bytes []byte) (ret string)

func CreateTimestampField

func CreateTimestampField(field *domain.DefField, fieldWithValue *domain.FieldWithValues)

func CreateTimestampSectionValue

func CreateTimestampSectionValue(section string, values *[]interface{})

func CreateUlidField

func CreateUlidField(field *domain.DefField, fieldWithValue *domain.FieldWithValues)

func Escape

func Escape(in string, shouldEscape []rune) (out string)

func EscapeColumnOfMysql

func EscapeColumnOfMysql(in string) string

func EscapeColumnOfSqlServer

func EscapeColumnOfSqlServer(in string) string

func EscapeValueOfMysql

func EscapeValueOfMysql(in string) string

func EscapeValueOfOracle

func EscapeValueOfOracle(in string) string

func EscapeValueOfSqlServer

func EscapeValueOfSqlServer(in string) string

func FormatPan

func FormatPan(cardType string, pan string) string

func FormatStr

func FormatStr(format string, val interface{}, precision int) (ret string, pass bool)

func GenBigint

func GenBigint(hasSign bool) (ret, note string)

func GenBin

func GenBin() (from, format string)

func GenBit

func GenBit() (ret, note string)

func GenChar

func GenChar(param string) (ret string, loop string)

func GenDate

func GenDate() (rang, typ, format string)

date time

func GenDatetime

func GenDatetime() (rang, typ, format string)

func GenDecimal

func GenDecimal(hasSign bool) (ret, note string)

func GenDefByColumnType

func GenDefByColumnType(param string, ret *FieldTypeInfo)

func GenDouble

func GenDouble(hasSign bool) (ret, note string)

func GenFloat

func GenFloat(hasSign bool) (ret, note string)

func GenInt

func GenInt(hasSign bool) (ret, note string)

func GenMediumint

func GenMediumint(hasSign bool) (ret, note string)

func GenSmallint

func GenSmallint(hasSign bool) (ret, note string)

func GenTime

func GenTime() (rang, typ, format string)

func GenTimestamp

func GenTimestamp() (rang, typ, format string)

func GenTinyint

func GenTinyint(hasSign bool) (ret, note string)

func GenYear

func GenYear() (rang, typ, format string)

func GenerateCVV

func GenerateCVV(size int) string

func GenerateCreditCard

func GenerateCreditCard(cardType string) (ret string)

func GenerateIdCard

func GenerateIdCard() (ret string)

func GenerateItems

func GenerateItems[TV ValType, TS StepType](start, end TV, step TS,
	precision int, isRand bool, repeat int, repeatTag string, count int) (
	arr []interface{})

func GenerateMac

func GenerateMac() (ret string)

func GenerateTimeItems

func GenerateTimeItems(start int64, end int64, step int, unit string, repeat int, repeatTag string) []interface{}

func GenerateToken

func GenerateToken(format string) (ret string)

func GenerateUlid

func GenerateUlid(format string) (ret string)

func GenerateUuid

func GenerateUuid(format string) (ret string)

func GetColumnType

func GetColumnType(metaType string, name string, records []interface{}, info *FieldTypeInfo)

func GetDefFromYamlFile

func GetDefFromYamlFile(path string) (po *model.ZdDef, content string, err error)

func GetDefFromYamlString

func GetDefFromYamlString(content string) (po *model.ZdDef, err error)

func GetFilesAndDirs

func GetFilesAndDirs(pth, typ string, res *map[string][]domain.ResFile)

func GetPinyin

func GetPinyin(word string) string

func GetPrecision

func GetPrecision(base float64, step interface{}) (precision int, newStep float64)

func GetPrecisionByRecords

func GetPrecisionByRecords(records []interface{}, info *FieldTypeInfo)

func GetRandFromList

func GetRandFromList(list []string, repeat, count int) (ret []interface{})

func GetRandValuesFromRange

func GetRandValuesFromRange(dataType, start, end, step string, repeat int, repeatTag, precisionStr string,
	format string, count int) (ret []interface{})

func GetRes

func GetRes() (ret map[string][]domain.ResFile, nameWidth, titleWidth int)

func GetSignByRecords

func GetSignByRecords(records []interface{}, info *FieldTypeInfo)

func GetType

func GetType(value interface{}) string

func GetValue

func GetValue[TV ValType, TS StepType](start TV, step TS, precision int, it, limit int64, isRand bool) (ret TV)

func GetVarcharTypeByName

func GetVarcharTypeByName(name string) (ret consts.VarcharType)

func GetVarcharTypeByRecords

func GetVarcharTypeByRecords(records []interface{}) (ret consts.VarcharType)

func GetYamlResType

func GetYamlResType(def domain.DefInfo) string

func InterfaceToStr

func InterfaceToStr(val interface{}) string

func IsFinish

func IsFinish[TV ValType, TS StepType](a interface{}, b TV, step TS) bool

func IsFromProtobuf

func IsFromProtobuf(file string) bool

func IsIDCard

func IsIDCard(id string) bool

func IsMobilePhone

func IsMobilePhone(str string) (ret bool)

func IsSelectExcelWithExpr

func IsSelectExcelWithExpr(field domain.DefField) bool

func IsTelPhone

func IsTelPhone(str string) (ret bool)

func ListData

func ListData()

func ListRes

func ListRes() (ret map[string][]domain.ResFile)

func LoadRes

func LoadRes(res map[string][]domain.ResFile) (ret map[string][]domain.ResFile, nameWidth, titleWidth int)

func Md5

func Md5(str string) (ret string)

func ParseBool

func ParseBool(str string) (ret bool)

func ParseInt

func ParseInt(str string) (ret int)

func PathToName

func PathToName(path, key, tp string) string

func PrintRes

func PrintRes(res map[string][]domain.ResFile, nameWidth, titleWidth int)

func RandDate

func RandDate() time.Time

RandDate 返回随机时间,时间区间从 1970 年 ~ 2020 年

func RandPassword

func RandPassword(length int) string

func ReadExcelInfo

func ReadExcelInfo(path string) (title, desc, resType string)

func ReadTextInfo

func ReadTextInfo(path, key string) (title, desc, resType string)

func ReadYamlData

func ReadYamlData(path string) (typ string, insts domain.ResInstances, ranges domain.ResRanges)

func ReadYamlInfo

func ReadYamlInfo(path string) (title, desc, resType string)

func RepeatSameVal

func RepeatSameVal[TV ValType](val TV, repeat int, arr *[]interface{})

func ReplaceSpecialChars

func ReplaceSpecialChars(bytes []byte) []byte

func Set

func Set()

func SetIsNum

func SetIsNum(info *FieldTypeInfo)

func Sha1

func Sha1(str string) (ret string)

func SortByName

func SortByName(arr []domain.ResFile) []domain.ResFile

func UrlEncode

func UrlEncode(str string) (ret string)

func VerifyCode

func VerifyCode(cardId string) string

VerifyCode 通过给定的身份证号生成最后一位的 VerifyCode

func View

func View(res string)

Types

type CardProperties

type CardProperties struct {
	LongName string
	Prefix   []string
	PanSize  int
	CvvSize  int
}

type CreditCard

type CreditCard struct {
	Issuer     string     `json:"issuer"`
	Pan        PAN        `json:"pan"`
	ExpiryDate ExpiryDate `json:"expiryDate"`
	CVV        string     `json:"cvv"`
}

type ExpiryDate

type ExpiryDate struct {
	Month int `json:"month"`
	Year  int `json:"year"`
}

func GenerateExpiryDate

func GenerateExpiryDate() ExpiryDate

type FieldTypeInfo

type FieldTypeInfo struct {
	ColumnType  consts.ColumnType
	VarcharType consts.VarcharType

	IsNum     bool
	Precision int
	HasSign   bool

	Note    string
	Rang    string
	Loop    string
	Loopfix string
	Type    string
	Format  string
	From    string
	Use     string
	Select  string
	Prefix  string
}

func GenerateFieldDefByMetadata

func GenerateFieldDefByMetadata(metadata string, param string, name string, records []interface{}) (info FieldTypeInfo)

type PAN

type PAN struct {
	Raw       string `json:"raw"`
	Formatted string `json:"formatted"`
}

func GeneratePAN

func GeneratePAN(properties CardProperties) PAN

type StepType

type StepType interface {
	int64 | float64
}

type ValType

type ValType interface {
	int64 | byte | float64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL