data

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MulanPSL-2.0 Imports: 8 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AAA2Int

func AAA2Int(colName string) (colIndex int)

AAA2Int 将表格列名(string)转换为列索引(int)

Example
s := AAA2Int("AAA")
fmt.Println(s)
Output:

703

func An2cn

func An2cn(an int) (string, error)
Example
s, _ := An2cn(1000006002400)
fmt.Println(s)
Output:

一万亿零六百万零二千四百

func Avg

func Avg[T Ordered](array []T) T

func Cn2an

func Cn2an(cn string) (int, error)

Cn2an 将中文数字转换为阿拉伯数字,不支持小数

Example
n, _ := Cn2an("一万亿零六百万零二千四百")
fmt.Println(n)
Output:

1000006002400

func Contains

func Contains[E comparable](array []E, ele E) bool

Contains 判断切片 array 中是否包含元素 ele

Example
fmt.Println(Contains([]string{"a", "B", "c"}, "a"))
fmt.Println(Contains([]string{"a", "B", "c"}, "b"))
Output:

true
false

func Equal

func Equal[E comparable](a, b []E) (bool, int)

Equal 简单比较两切片内元素是否相同,并返回第一个不相同索引

如果相同返回-2,如果长度不同返回-1
Example
s, i := Equal([]string{"1"}, []string{"1"})
fmt.Println(s, i)

s, i = Equal([]int{1}, []int{2})
fmt.Println(s, i)
Output:

true -2
false 0

func IndexS

func IndexS[E comparable](array []E, ele E) int

IndexS 判断切片 array 中元素 ele 的索引

Example
fmt.Println(IndexS([]string{"a", "B", "c"}, "a"))
fmt.Println(IndexS([]string{"a", "B", "c"}, "b"))
Output:

0
-1

func Insert

func Insert[E comparable](array []E, index int, elem ...E) []E

Insert 向切片中插入元素,返回新的切片

Example
a := []int{1, 2, 3, 4, 5}
a = Insert(a, 2, 7, 8, 9)
fmt.Println(a)
Output:

[1 2 7 8 9 3 4 5]

func Int2AAA

func Int2AAA(colIndex int) (colName string)

Int2AAA 将表格列索引(int)转换为列名(string)

Example
s := Int2AAA(703)
fmt.Println(s)
Output:

AAA

func IsEmpty

func IsEmpty(array []string) bool

IsEmpty 判断切片是否为空

func Max

func Max[E Ordered](array []E) E

func Min

func Min[T Ordered](array []T) T

func Pop

func Pop[E comparable](array []E, index int) ([]E, E)

Pop 根据索引删除切片中的元素,返回新的切片,和删除的元素

Example
a := []int{1, 2, 3, 4, 5}
a, b := Pop(a, -3)
fmt.Println(a, b)
Output:

[1 2 4 5] 3

func RepeatIndex

func RepeatIndex[E comparable](array []E) map[E][]int

RepeatIndex 提取切片内重复值的索引

Example
a := []int{1, 3, 5, 7, 9, 2, 5, 3, 7, 1, 10}
fmt.Println(RepeatIndex(a))
Output:

map[1:[0 9] 3:[1 7] 5:[2 6] 7:[3 8]]

Types

type JsonString

type JsonString string

func (JsonString) Check

func (j JsonString) Check() bool

Check 检查是否为json字符串

func (JsonString) Find

func (j JsonString) Find(relational string) (any, error)

Find 查询方法

Example
j := JsonString(`{"name":"jjs","age":18,"love":[123,45],"info":{"grade":7,"d":[60,70,80,90],"desc":"good"},"s":{"a":1,"b":2}}`)

find, _ := j.Find("info.d.[0]")
fmt.Println(find)

find = j.FindInt("info.grade")
fmt.Println(find)
Output:

60
7

func (JsonString) FindBool

func (j JsonString) FindBool(relational string) bool

FindBool 返回布尔值

func (JsonString) FindFloat

func (j JsonString) FindFloat(relational string) float64

FindFloat 返回浮点数

func (JsonString) FindInt

func (j JsonString) FindInt(relational string) int

FindInt 返回整数

func (JsonString) FindString

func (j JsonString) FindString(relational string) string

FindString 返回字符串

type MD5

type MD5 string

MD5 代价密字符串

Example
var s MD5 = "123456"
fmt.Println(s.Encrypt())
fmt.Println(s.Encrypt().IsBig())
fmt.Println(s.Encrypt().IsShort().IsBig())
fmt.Printf("%T %s", s.Encrypt(), s.Encrypt().ToString())
Output:

e10adc3949ba59abbe56e057f20f883e
E10ADC3949BA59ABBE56E057F20F883E
49BA59ABBE56E057
data.MD5 e10adc3949ba59abbe56e057f20f883e

func (MD5) Encrypt

func (m MD5) Encrypt() MD5

Encrypt 默认加密 32位小写

func (MD5) IsBig

func (m MD5) IsBig() MD5

func (MD5) IsShort

func (m MD5) IsShort() MD5

func (MD5) ToString

func (m MD5) ToString() string

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float64 | ~float32
}

Jump to

Keyboard shortcuts

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