util

package module
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: GPL-2.0 Imports: 28 Imported by: 1

README

Util

GoReport Gitea Release Go.Dev reference

import "git.viry.cc/gomod/util"
  • CRC32
  • MD5 (File, reader, string, bytes)
  • SHA1 (File, reader, string, bytes)
  • SHA256 (File, reader, string, bytes)
  • SHA512 (File, reader, string, bytes)
  • AES (CBC)
  • Base64
  • bytes to int (uint16, uint32, uint64)
  • int to bytes (uint16, uint32, uint64)
  • Bytes Combine
  • Bit Set
  • JSON
  • Slice Remove Duplicates
  • File Stat
  • Dir List
  • Mkdir
  • Dir Size
  • Size Unit, Decimal System and Binary System
  • Path Split
  • Random String, Key
  • IP
  • Time Calculate
  • Tcp Port Checker
  • Port
  • Get Client IP & HTTP GET/POST/PUT Request & HTTP Response & Redirect

CRC32 & MD5 & SHA1 & SHA256 & SHA512

各类型提供的函数方法名称类似,只需要将函数名中的CRC32替换为其他类型名即可使用

以下以CRC32为例子

  • 计算结果为*CRC32Result类型,可通过以下方法获取不同类型结果
  • .Value() uint32 CRC32独有
  • .Array() [4]byte 各类型长度不一致
  • .Slice() []byte
  • .Upper() string
  • .Lower() string
  • .Error() error 获取计算过程中产生的错误

NewCRC32()

// 示例
fmt.Println(NewCRC32().FromString("Akvicor").Lower())
  • .FromReader() 从Reader中读取数据并计算
  • .FromFile() 从文件中读取数据并计算
  • .FromReaderChunk() 从Reader中分块读取数据并计算
  • .FromFileChunk() 从文件中分块读取数据并计算
  • .FromBytes() 计算byte数组
  • .FromString() 计算字符串

NewCRC32Pip()

// 示例
cp := NewCRC32Pip()
io.WriteString(cp, "Akvicor")
fmt.Println(cp.Result().Value())
  • .Write() Writer实现
  • .WriteBytes() 写入[]byte
  • .WriteString() 写入string
  • .Result() 获取计算结果

AES

  • 计算结果为*AESResult类型,可通过以下方法获取不同类型结果
  • .Bytes() []byte
  • .Base64() *Base64Result
  • .String() string
  • .Upper() string
  • .Lower() string
  • .Encrypted() bool
  • .Decrypt(key []byte, iv ...[]byte) *AESResult
  • .Encrypt(key []byte, iv ...[]byte) *AESResult
  • .Error() error 获取计算过程中产生的错误

NewAESResult()

  • .EncryptCBC(origData, key []byte, iv ...[]byte) *AESResult
  • .DecryptCBC(encrypted, key []byte, iv ...[]byte) *AESResult

Base64

  • 计算结果为*Base64Result类型,可通过以下方法获取不同类型结果
  • .Bytes() []byte
  • .String() string
  • .Error() error 获取计算过程中产生的错误

NewBase64()

  • .EncodeBytes() 编码[]byte
  • .EncodeString() 编码string
  • .DecodeBytes() 解码[]byte
  • .DecodeString() 解码string

[]byte <-> uint

支持16/32/64位无符号整型,以下仅列出16位相关函数

  • .UInt16ToBytesSlice() uint16[]byte
  • .BytesSliceToUInt16() []byteuint16
  • .UInt16ToBytesArray() uint16[...]byte
  • .BytesArrayToUInt16() [...]byteuint16

Bytes Combine

合并多个[]byte

b := BytesCombine([]byte{0x11, 0x22}, []byte{0x33, 0x44, 0x55}, []byte{0x66})

Bit Set

设置整型变量二进制位,支持byte,uint8,int8,uint16,int16,uint32,int32,uint64,int64

b8 := uint8(0)
BitSet(&b8, 0, true)

JSON

type TestStruct struct {
Name string `json:"name"`
Age  int    `json:"age"`
}
test1 := TestStruct{
Name: "Akvicor",
Age:  17,
}

fmt.Println(NewJSON(&test1, false).String())
fmt.Println(NewJSONResult([]byte(`{"name":"Akvicor","age":17}`)).Map())
  • NewJSONResult(data []byte) *JSON 传入json格式数据并储存,自动判断是json对象还是json数组
  • NewJSON(v any, isArray bool) *JSON 将传入变量转为json并储存,通过isArray指名传入的是否是数组
  • 计算结果为*JSON类型,可通过以下方法获取不同类型结果
  • .Bytes() []byte
  • .String() string
  • .Map(idx ...int) map[string]any 返回json对象,如果变量中保存的是json数组,返回idx位置的对象,默认为0
  • .MapArray() []map[string]any 返回json数组,如果变量中保存的是json对象,自动创建一个数组并将变量作为数组第一个元素
  • .Error() error 获取计算过程中产生的错误

Slice Remove Duplicates

Slice去除重复元素

  • NewRemoveDuplicates() *RemoveDuplicates
  • .String(s []string) []string
  • .Byte(s []byte) []byte
  • .Int8(s []int8) []int8
  • .Int16(s []int16) []int16
  • .Int(s []int) []int
  • .Int32(s []int32) []int32
  • .Int64(s []int64) []int64
  • .UInt8(s []uint8) []uint8
  • .UInt16(s []uint16) []uint16
  • .UInt(s []uint) []uint
  • .UInt32(s []uint32) []uint32
  • .UInt64(s []uint64) []uint64
  • .Float32(s []float32) []float32
  • .Float64(s []float64) []float64

File Stat

判断文件类型(不存在,是文件夹,是文件

FileStat(filename string) *FileStatModel

通过以下函数确定文件类型

IsFile()
NotFile()
IsDir()
NotDir()
IsExist()
NotExist()
IsDenied()
NotDenied()
IsError()
NotError()

Dir List

获取文件列表

DirList(p string) *DirListModel

type DirListModel struct {
    Files []DirListUnitModel
    Dirs  []DirListUnitModel
    Error error
}

type DirListUnitModel struct {
    Name    string
    Size    int64
    Mode    fs.FileMode
    ModTime time.Time
}

Mkdir

创建文件夹

MkdirP(p string, perm ...os.FileMode) error

Mkdir

获取文件夹大小

DirSize(p string) (int64, error)

Size Unit, Decimal System and Binary System

将大小单位B转换为K,M,G,T,P,E,并支持返回格式化后的字符串

  • KiB,MiB,GiB,TiB,PiB,EiB为单位(1024进制
  • KB,MB,GB,TB,PB,EB为单位(1000进制
  • K,M,G,T,P,E为单位(转换为iBB时,按照1024进制处理
  • 将B单位的值格式化到各个单位(如1025B返回1KiB 1B,返回string[]*SizeFormatModel
  • 截取最大的单位的大小(如1M2B返回1M
Size(1*SizeB + 2*SizeKiB).Format(",", true)
Size(1*SizeB + 2*SizeKB).Format(",", true)

Path Split

三种方法分割路径字符串

  • SplitPathSkip(p string, skip int) (head, tail string) 跳过skip个/后,在下一个/处分割,且/保留在tail中
  • SplitPath(p string) (head, tail string) 在第一个/处分割,且/保留在tail中
  • SplitPathRepeat(p string, repeat int) (head, tail string) 在第一个/处分割,且/保留在tail中,将tail作为参数再次分割,重复repeat次

Random String, Key

返回随机字符串

字符

  • RandomLower 小写字母
  • RandomUpper 大写字母
  • RandomDigit 数字
  • RandomSpecial 特殊字符
  • RandomAlpha 字母
  • RandomAll 各类字符拼接成的单个字符串
  • RandomSlice 各类型字符组成的字符串数组

方法

  • RandomString(length int, str ...string) 随机生成,默认通过RandomAll生成,也可通过传入str来自定义
  • RandomStringAtLeastOnce(length int, str ...string) 每种类型至少包含一个,每个str元素为一个类型,默认通过RandomSlice生成,也可通过传入str来自定义
  • RandomStringWithTimestamp(length int, unix ...int64) 长度至少为8,返回包含时间戳的随机字符串
  • ParseRandomStringWithTimestamp(str string) (int64, string) 解析包含时间戳的随机字符串
  • RandomKey(l int) *KeyResult 生成一个长度为l的key的byte数组, 返回包含key的结构体
  • KeyResultFromHexString(hx string) *KeyResult 解析hex字符串,转换为KeyResult

KeyResult下的方法

  • .Bytes 返回key的byte数组
  • .Upper 返回hex后的大写字符串,长度为Bytes的两倍
  • .Lower 返回hex后的小写字符串,长度为Bytes的两倍
  • .Error

IP

  • IsIPAddr 判断是否是ip地址
  • IsLocalIPAddr 判断ip地址是否是本地ip
  • IsLocalIP 判断ip是否是本地ip
  • IPAddrToUint32 ip地址转为uint32
  • Uint32ToIPAddr uint32转为ip地址
  • IPToUint32 ip转为uint32
  • Uint32ToIP uint32转为ip
  • GetLocalIp 获取本地IP

Time Calculate

  • TimeNowFormat 返回当前时间的格式化字符串
  • TimeNowToBase36 返回当前时间的36进制字符串
  • TimeUnixToFormat unix转为格式化字符串
  • TimeUnixToBase36 unix转为36进制字符串
  • TimeBase36ToUnix 36进制字符串转为unix
  • YearBetweenTwoDate 计算两个日期年份相减,不计算月等等
  • YearBetweenTwoTime 计算两个日期间隔的年份,计算到秒
  • MonthBetweenTwoDate 计算两个日期相差月份,不计算日等等
  • MonthBetweenTwoTime 计算两个日期相差月份,计算到秒
  • DayBetweenTwoDate 计算两个日期相差天数,不计算小时等等
  • DayBetweenTwoTime 计算两个日期相差天数,计算到秒
  • HourBetweenTwoTime 计算两个日期相差小时
  • MinuteBetweenTwoTime 计算两个日期相差分钟
  • SecondBetweenTwoTime 计算两个日期相差秒

Tcp Port Checker

检测端口是否开放

  • TcpPortIsOpen(ip, port string)
  • TcpPortIsOpenByAddr(ipPort string)

Port

获取可用端口

  • GetAvailablePort() (int, error)

Get Client IP & HTTP GET/POST/PUT Request & HTTP Response & Redirect

获取IP

  • RemoteIP 通过RemoteAddr获取ip
  • GetClientIP 获取客户端ip,包含内网地址
  • GetClientPublicIP 获取客户端ip

页面跳转

  • RespRedirect 重定向
  • LastPage 上一个页面
  • Reload 刷新页面

API响应

  • NewHTTPResp 创建响应数据结构体变量
  • ParseHTTPResp 解析json字符串为响应数据结构体变量
  • WriteHTTPRespAPIOk 返回 ok
  • WriteHTTPRespAPIFailed 返回 failed
  • WriteHTTPRespAPIInvalidKey 返回 非法的key
  • WriteHTTPRespAPIInvalidInput 返回 非法的输入
  • WriteHTTPRespAPIProcessingFailed 返回 处理失败

GET & POST

Content Type

  • HTTPContentTypeUrlencoded
  • HTTPContentTypeUrlencodedUTF8
  • HTTPContentTypeJson
  • HTTPContentTypeJsonUTF8
  • HTTPContentTypeXml
  • HTTPContentTypeXmlUTF8
  • HTTPContentTypePlain
  • HTTPContentTypePlainUTF8
  • HTTPContentTypeHtml
  • HTTPContentTypeHtmlUTF8
  • HTTPContentTypeFormData
  • HTTPContentTypeFormDataUTF8

方法

  • HttpGet(u string, args any) u为url,args为可序列化变量
  • HttpPost(contentType string, u string, args any)
  • HttpPostGet(contentType string, u string, argsGET, argsPOST any)

Documentation

Index

Examples

Constants

View Source
const (
	HTTPRespCodeOKCode               HTTPRespCode = 0
	HTTPRespCodeOKMsg                string       = "ok"
	HTTPRespCodeERCode               HTTPRespCode = 1
	HTTPRespCodeERMsg                string       = "failed to respond"
	HTTPRespCodeInvalidKeyCode       HTTPRespCode = 2
	HTTPRespCodeInvalidKeyMsg        string       = "invalid key"
	HTTPRespCodeProcessingFailedCode HTTPRespCode = 3
	HTTPRespCodeProcessingFailedMsg  string       = "processing failed"
	HTTPRespCodeInvalidInputCode     HTTPRespCode = 4
	HTTPRespCodeInvalidInputMsg      string       = "invalid input"
)
View Source
const (
	HTTPContentTypeUrlencoded     = "application/x-www-form-urlencoded"
	HTTPContentTypeUrlencodedUTF8 = "application/x-www-form-urlencoded; charset=utf-8"
	HTTPContentTypeJson           = "application/json"
	HTTPContentTypeJsonUTF8       = "application/json; charset=UTF-8"
	HTTPContentTypeXml            = "application/xml"
	HTTPContentTypeXmlUTF8        = "application/xml; charset=UTF-8"
	HTTPContentTypePlain          = "text/plain"
	HTTPContentTypePlainUTF8      = "text/plain; charset=utf-8"
	HTTPContentTypeHtml           = "text/html"
	HTTPContentTypeHtmlUTF8       = "text/html; charset=utf-8"
	HTTPContentTypeFormData       = "multipart/form-data"
	HTTPContentTypeFormDataUTF8   = "multipart/form-data; charset=utf-8"
)
View Source
const (
	SizeKilobyte = 1000 * SizeByte
	SizeMegabyte = 1000 * SizeKilobyte
	SizeGigabyte = 1000 * SizeMegabyte
	SizeTerabyte = 1000 * SizeGigabyte
	SizePetabyte = 1000 * SizeTerabyte
	SizeExabyte  = 1000 * SizePetabyte
)

Decimal System

View Source
const (
	SizeKB = SizeKilobyte
	SizeMB = SizeMegabyte
	SizeGB = SizeGigabyte
	SizeTB = SizeTerabyte
	SizePB = SizePetabyte
	SizeEB = SizeExabyte
)
View Source
const (
	SizeKBSymbol = "KB"
	SizeMBSymbol = "MB"
	SizeGBSymbol = "GB"
	SizeTBSymbol = "TB"
	SizePBSymbol = "PB"
	SizeEBSymbol = "EB"
)
View Source
const (
	SizeKibibyte = 1024 * SizeByte
	SizeMebibyte = 1024 * SizeKibibyte
	SizeGigibyte = 1024 * SizeMebibyte
	SizeTebibyte = 1024 * SizeGigibyte
	SizePebibyte = 1024 * SizeTebibyte
	SizeExbibyte = 1024 * SizePebibyte
)

Binary System

View Source
const (
	SizeKiB = SizeKibibyte
	SizeMiB = SizeMebibyte
	SizeGiB = SizeGigibyte
	SizeTiB = SizeTebibyte
	SizePiB = SizePebibyte
	SizeEiB = SizeExbibyte
)
View Source
const (
	SizeKiBSymbol = "KiB"
	SizeMiBSymbol = "MiB"
	SizeGiBSymbol = "GiB"
	SizeTiBSymbol = "TiB"
	SizePiBSymbol = "PiB"
	SizeEiBSymbol = "EiB"
)
View Source
const (
	SizeBSymbol = "B"
	SizeKSymbol = "K"
	SizeMSymbol = "M"
	SizeGSymbol = "G"
	SizeTSymbol = "T"
	SizePSymbol = "P"
	SizeESymbol = "E"
)
View Source
const MD5ResultLength = 16
View Source
const RandomAlpha = RandomLower + RandomUpper
View Source
const RandomDigit = "0123456789"
View Source
const RandomLower = "abcdefghijklmnopqrstuvwxyz"
View Source
const RandomSpecial = "!_.~?-+=#@$%"
View Source
const RandomStringWithTimestampTimeLength = 8
View Source
const RandomUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const SHA1ResultLength = 20
View Source
const SHA256ResultLength = 32
View Source
const SHA512ResultLength = 64
View Source
const TimeFormatLayout = "2006-01-02 15:04:05"

Variables

View Source
var ErrorInvalidIPV4Format = errors.New("invalid ipv4 format")

Functions

func BitSet

func BitSet(b any, bit byte, set bool)
Example
v := 0
BitSet(&v, 1, true)
fmt.Println(v)
ui := uint8(0)
BitSet(&ui, 7, true)
fmt.Println(ui)
i := int8(0)
BitSet(&i, 7, true)
fmt.Println(i)
Output:

2
128
-128

func BytesArrayToUInt16 added in v1.7.1

func BytesArrayToUInt16(buf [2]byte) uint16
Example
bs := [2]byte{255, 255}
val := BytesArrayToUInt16(bs)
fmt.Println(val)

bs = [2]byte{127, 255}
val = BytesArrayToUInt16(bs)
fmt.Println(val)

bs = [2]byte{127, 254}
val = BytesArrayToUInt16(bs)
fmt.Println(val)
Output:

65535
32767
32766

func BytesArrayToUInt32 added in v1.7.1

func BytesArrayToUInt32(buf [4]byte) uint32
Example
bs := [4]byte{255, 255, 255, 255}
val := BytesArrayToUInt32(bs)
fmt.Println(val)

bs = [4]byte{127, 255, 255, 255}
val = BytesArrayToUInt32(bs)
fmt.Println(val)

bs = [4]byte{127, 254, 254, 254}
val = BytesArrayToUInt32(bs)
fmt.Println(val)
Output:

4294967295
2147483647
2147417854

func BytesArrayToUInt64 added in v1.7.1

func BytesArrayToUInt64(buf [8]byte) uint64
Example
bs := [8]byte{255, 255, 255, 255, 255, 255, 255, 255}
val := BytesArrayToUInt64(bs)
fmt.Println(val)

bs = [8]byte{127, 255, 255, 255, 255, 255, 255, 255}
val = BytesArrayToUInt64(bs)
fmt.Println(val)

bs = [8]byte{127, 254, 254, 254, 254, 254, 254, 254}
val = BytesArrayToUInt64(bs)
fmt.Println(val)
Output:

18446744073709551615
9223372036854775807
9223089458054627070

func BytesCombine

func BytesCombine(pBytes ...[]byte) []byte
Example
b1 := []byte{11, 22}
b2 := []byte{33, 44, 55}
b3 := []byte{66}

fmt.Println(BytesCombine(b1, b2, b3))
Output:

[11 22 33 44 55 66]

func BytesSliceToUInt16 added in v1.7.1

func BytesSliceToUInt16(buf []byte) uint16
Example
bs := []byte{255, 255}
val := BytesSliceToUInt16(bs)
fmt.Println(val)

bs = []byte{127, 255}
val = BytesSliceToUInt16(bs)
fmt.Println(val)

bs = []byte{127, 254}
val = BytesSliceToUInt16(bs)
fmt.Println(val)
Output:

65535
32767
32766

func BytesSliceToUInt32 added in v1.7.1

func BytesSliceToUInt32(buf []byte) uint32
Example
bs := []byte{255, 255, 255, 255}
val := BytesSliceToUInt32(bs)
fmt.Println(val)

bs = []byte{127, 255, 255, 255}
val = BytesSliceToUInt32(bs)
fmt.Println(val)

bs = []byte{127, 254, 254, 254}
val = BytesSliceToUInt32(bs)
fmt.Println(val)
Output:

4294967295
2147483647
2147417854

func BytesSliceToUInt64 added in v1.7.1

func BytesSliceToUInt64(buf []byte) uint64
Example
bs := []byte{255, 255, 255, 255, 255, 255, 255, 255}
val := BytesSliceToUInt64(bs)
fmt.Println(val)

bs = []byte{127, 255, 255, 255, 255, 255, 255, 255}
val = BytesSliceToUInt64(bs)
fmt.Println(val)

bs = []byte{127, 254, 254, 254, 254, 254, 254, 254}
val = BytesSliceToUInt64(bs)
fmt.Println(val)
Output:

18446744073709551615
9223372036854775807
9223089458054627070

func BytesToUInt

func BytesToUInt(buf []byte) uint64
Example
bs := []byte{255}
fmt.Println(BytesToUInt(bs))
bs = []byte{255, 255}
fmt.Println(BytesToUInt(bs))
bs = []byte{255, 255, 255, 255}
fmt.Println(BytesToUInt(bs))
bs = []byte{255, 255, 255, 255, 255, 255, 255, 255}
fmt.Println(BytesToUInt(bs))
bs = []byte{255, 255, 255, 255, 255, 255, 255}
fmt.Println(BytesToUInt(bs))
Output:

255
65535
4294967295
18446744073709551615
72057594037927935

func DayBetweenTwoDate added in v1.7.1

func DayBetweenTwoDate(t1, t2 time.Time) int64
Example
t1 := int64(1705628326)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(DayBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(DayBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(DayBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2024-01-19 09:38:46 -> 2024-01-18 22:37:45
0
1
-1

func DayBetweenTwoTime added in v1.7.1

func DayBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1705628326)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(DayBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(DayBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(DayBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2024-01-19 09:38:46 -> 2024-01-18 22:37:45
0
0
0

func DirSize added in v1.10.2

func DirSize(p string) (int64, error)
Example
p, err := DirSize("./testfile")
if err != nil {
	fmt.Println(err)
}
fmt.Println(p)
Output:

func GetAvailablePort added in v1.10.2

func GetAvailablePort() (int, error)
Example
p, err := GetAvailablePort()
if err != nil {
	fmt.Println(err)
}
fmt.Println(p)
Output:

func GetClientIP added in v1.7.1

func GetClientIP(r *http.Request) string

func GetClientPublicIP added in v1.7.1

func GetClientPublicIP(r *http.Request) string

func GetLocalIp added in v1.10.2

func GetLocalIp() (string, error)
Example
p, err := GetLocalIp()
if err != nil {
	fmt.Println(err)
}
fmt.Println(p)
Output:

func HourBetweenTwoTime added in v1.7.1

func HourBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1705628326)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(HourBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(HourBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(HourBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2024-01-19 09:38:46 -> 2024-01-18 22:37:45
0
11
-11

func HttpGet added in v1.7.1

func HttpGet(u string, args any, contentType string, header map[string]string) []byte
Example
i := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts/1", nil, HTTPContentTypePlain, nil))
i1 := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts", map[string]any{"id": 1}, HTTPContentTypePlain, nil))
i2 := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts", map[string]any{"id": 2}, HTTPContentTypePlain, nil))
if fmt.Sprint(i.Map()["id"]) != "1" {
	fmt.Println(i)
}
if fmt.Sprint(i1.Map()["id"]) != "1" {
	fmt.Println(i1)
}
if fmt.Sprint(i2.MapArray()[0]["id"]) != "2" {
	fmt.Println(i2)
}
Output:

func HttpPost added in v1.7.1

func HttpPost(u string, args any, contentType string, header map[string]string) []byte
Example
i1 := NewJSONResult(HttpPost("https://jsonplaceholder.typicode.com/posts", map[string]any{"title": "t1", "body": "b1", "userId": 1}, HTTPContentTypeUrlencoded, nil))
if fmt.Sprint(i1.Map()["id"]) != "101" {
	fmt.Println(i1)
}
Output:

func HttpPostGet added in v1.7.1

func HttpPostGet(u string, argsGET, argsPOST any, contentType string, header map[string]string) []byte
Example
i1 := NewJSONResult(HttpPostGet("https://jsonplaceholder.typicode.com/posts", map[string]any{"title": "t2", "body": "b2", "userId": 2}, map[string]any{"title": "t1", "body": "b1", "userId": 1}, HTTPContentTypeUrlencoded, nil))
if fmt.Sprint(i1.Map()["id"]) != "101" {
	fmt.Println(i1)
}
Output:

func IPAddrToUint32 added in v1.7.1

func IPAddrToUint32(ip string) (uint32, error)

func IPToUint32 added in v1.7.1

func IPToUint32(ip net.IP) (uint32, error)

func IsIPAddr added in v1.7.1

func IsIPAddr(ip string) bool

func IsLocalIP added in v1.7.1

func IsLocalIP(ip net.IP) bool

func IsLocalIPAddr added in v1.7.1

func IsLocalIPAddr(ip string) bool

func LastPage added in v1.7.1

func LastPage(w http.ResponseWriter, r *http.Request)

func MinuteBetweenTwoTime added in v1.7.1

func MinuteBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1705628326)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MinuteBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(MinuteBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MinuteBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2024-01-19 09:38:46 -> 2024-01-18 22:37:45
0
661
-661

func MkdirP added in v1.10.2

func MkdirP(p string, perm ...os.FileMode) error
Example
err := MkdirP("testfile/testfile")
if err != nil {
	fmt.Println(err)
}
Output:

func MonthBetweenTwoDate added in v1.7.1

func MonthBetweenTwoDate(t1, t2 time.Time) int64
Example
t1 := int64(1739929126)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211064)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211066)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2025-02-19 09:38:46 -> 2024-01-18 22:37:45
0
13
-13
2025-01-18 22:37:44 -> 2024-01-18 22:37:45
12
-12
2025-01-18 22:37:46 -> 2024-01-18 22:37:45
12
-12

func MonthBetweenTwoTime added in v1.7.1

func MonthBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1739929126)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(MonthBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211064)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211066)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(MonthBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(MonthBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2025-02-19 09:38:46 -> 2024-01-18 22:37:45
0
13
-13
2025-01-18 22:37:44 -> 2024-01-18 22:37:45
11
-11
2025-01-18 22:37:46 -> 2024-01-18 22:37:45
12
-12

func ParseRandomStringWithTimestamp

func ParseRandomStringWithTimestamp(str string) (int64, string)

func RandomString

func RandomString(length int, str ...string) string
Example
if RandomString(0, "a") != "" {
	fmt.Println("1 failed")
}
if RandomString(0, "abc") != "" {
	fmt.Println("2 failed")
}
if RandomString(1, "b") != "b" {
	fmt.Println("3 failed")
}
if RandomString(7, "a") != "aaaaaaa" {
	fmt.Println("4 failed")
}
if RandomString(0, "a", "b") != "" {
	fmt.Println("5 failed")
}
str := RandomString(7)
if len(str) != 7 {
	fmt.Println("6 failed")
}
Output:

func RandomStringAtLeastOnce added in v1.7.1

func RandomStringAtLeastOnce(length int, str ...string) string
Example
if RandomStringAtLeastOnce(0, "a") != "" {
	fmt.Println("1 failed")
}
if RandomStringAtLeastOnce(0, "abc") != "" {
	fmt.Println("2 failed")
}
if RandomStringAtLeastOnce(1, "b") != "b" {
	fmt.Println("3 failed")
}
if RandomStringAtLeastOnce(7, "a") != "aaaaaaa" {
	fmt.Println("4 failed")
}
if RandomStringAtLeastOnce(0, "a", "b") != "" {
	fmt.Println("5 failed")
}
str := RandomStringAtLeastOnce(2, "a", "b")
if str != "ab" && str != "ba" {
	fmt.Println("6 failed", str)
}
if RandomStringAtLeastOnce(1, "a", "b") != "a" {
	fmt.Println("7 failed")
}
str = RandomStringAtLeastOnce(7)
if len(str) != 7 {
	fmt.Println("8 failed")
}
Output:

func RandomStringWithTimestamp

func RandomStringWithTimestamp(length int, unix ...int64) string
Example
t := time.Now().Unix()
rstr := RandomStringWithTimestamp(17, t)
date, str := ParseRandomStringWithTimestamp(rstr)
if t != date || str != rstr[RandomStringWithTimestampTimeLength:] {
	fmt.Printf("before [%d] [%s] after [%d][%s]\n", t, rstr, date, str)
}
Output:

func Reload added in v1.7.1

func Reload(w http.ResponseWriter, r *http.Request)

func RemoteIP added in v1.7.1

func RemoteIP(r *http.Request) string

func RespRedirect added in v1.7.1

func RespRedirect(w http.ResponseWriter, r *http.Request, url string)

func SecondBetweenTwoTime added in v1.7.1

func SecondBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1705628326)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(SecondBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(SecondBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(SecondBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2024-01-19 09:38:46 -> 2024-01-18 22:37:45
0
39661
-39661

func SplitPath

func SplitPath(p string) (head, tail string)
Example
test := func(s string) {
	head, tail := SplitPath(s)
	fmt.Printf("s[%s] -> [%s, %s]\n", s, head, tail)
}
test("/123/akvicor")
test("123/akvicor")
test("/akvicor")
test("akvicor")
test("/")
test("")
Output:

s[/123/akvicor] -> [/123, /akvicor]
s[123/akvicor] -> [/123, /akvicor]
s[/akvicor] -> [/akvicor, ]
s[akvicor] -> [/akvicor, ]
s[/] -> [/, ]
s[] -> [/, ]

func SplitPathRepeat

func SplitPathRepeat(p string, repeat int) (head, tail string)
Example
test := func(s string, repeat int) {
	head, tail := SplitPathRepeat(s, repeat)
	fmt.Printf("s[%s] repeat[%d] -> [%s, %s]\n", s, repeat, head, tail)
}
s := "/1/23/456/7/"
test(s, 0)
test(s, 1)
test(s, 2)
test(s, 3)
test(s, 4)
test(s, 5)
s = ""
test(s, 0)
test(s, 1)
s = "/"
test(s, 0)
test(s, 1)
s = "url"
test(s, 0)
test(s, 1)
s = "/url"
test(s, 0)
test(s, 1)
s = "url/"
test(s, 0)
test(s, 1)
s = "/url/"
test(s, 0)
test(s, 1)
Output:

s[/1/23/456/7/] repeat[0] -> [/1, /23/456/7]
s[/1/23/456/7/] repeat[1] -> [/23, /456/7]
s[/1/23/456/7/] repeat[2] -> [/456, /7]
s[/1/23/456/7/] repeat[3] -> [/7, ]
s[/1/23/456/7/] repeat[4] -> [/, ]
s[/1/23/456/7/] repeat[5] -> [/, ]
s[] repeat[0] -> [/, ]
s[] repeat[1] -> [/, ]
s[/] repeat[0] -> [/, ]
s[/] repeat[1] -> [/, ]
s[url] repeat[0] -> [/url, ]
s[url] repeat[1] -> [/, ]
s[/url] repeat[0] -> [/url, ]
s[/url] repeat[1] -> [/, ]
s[url/] repeat[0] -> [/url, ]
s[url/] repeat[1] -> [/, ]
s[/url/] repeat[0] -> [/url, ]
s[/url/] repeat[1] -> [/, ]

func SplitPathSkip

func SplitPathSkip(p string, skip int) (head, tail string)
Example
test := func(s string, skip int) {
	head, tail := SplitPathSkip(s, skip)
	fmt.Printf("s[%s] skip[%d] -> [%s, %s]\n", s, skip, head, tail)
}
s := "/1/23/456/7/"
test(s, 0)
test(s, 1)
test(s, 2)
test(s, 3)
test(s, 4)
s = ""
test(s, 0)
test(s, 1)
s = "/"
test(s, 0)
test(s, 1)
s = "url"
test(s, 0)
test(s, 1)
s = "/url"
test(s, 0)
test(s, 1)
s = "url/"
test(s, 0)
test(s, 1)
s = "/url/"
test(s, 0)
test(s, 1)
Output:

s[/1/23/456/7/] skip[0] -> [/1, /23/456/7]
s[/1/23/456/7/] skip[1] -> [/1/23, /456/7]
s[/1/23/456/7/] skip[2] -> [/1/23/456, /7]
s[/1/23/456/7/] skip[3] -> [/1/23/456/7, ]
s[/1/23/456/7/] skip[4] -> [/1/23/456/7, ]
s[] skip[0] -> [/, ]
s[] skip[1] -> [/, ]
s[/] skip[0] -> [/, ]
s[/] skip[1] -> [/, ]
s[url] skip[0] -> [/url, ]
s[url] skip[1] -> [/url, ]
s[/url] skip[0] -> [/url, ]
s[/url] skip[1] -> [/url, ]
s[url/] skip[0] -> [/url, ]
s[url/] skip[1] -> [/url, ]
s[/url/] skip[0] -> [/url, ]
s[/url/] skip[1] -> [/url, ]

func TcpPortIsOpen added in v1.7.1

func TcpPortIsOpen(ip, port string) bool
Example
ip := "172.16.0.1"
fmt.Println(TcpPortIsOpen(ip, "22"))
fmt.Println(TcpPortIsOpen(ip, "80"))
fmt.Println(TcpPortIsOpen(ip, "443"))
fmt.Println(TcpPortIsOpen(ip, "444"))
Output:

true
true
true
false

func TcpPortIsOpenByAddr added in v1.7.1

func TcpPortIsOpenByAddr(ipPort string) bool
Example
fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:22"))
fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:80"))
fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:443"))
fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:444"))
Output:

true
true
true
false

func TimeBase36ToUnix added in v1.7.1

func TimeBase36ToUnix(t string) int64
Example
t := TimeBase36ToUnix("s7ijax")
fmt.Println(t)
t = TimeBase36ToUnix("00s7ijax")
fmt.Println(t)
Output:

1705675065
1705675065

func TimeNowFormat added in v1.7.1

func TimeNowFormat() string
Example
t := TimeNowFormat()
if len(t) != 19 {
	fmt.Println(t)
}
Output:

func TimeNowToBase36 added in v1.7.1

func TimeNowToBase36(length ...int) string
Example
s := TimeNowToBase36()
if len(s) < 1 {
	fmt.Println(s)
}
s = TimeNowToBase36(8)
if len(s) != 8 {
	fmt.Println(s)
}
Output:

func TimeUnixToBase36 added in v1.7.1

func TimeUnixToBase36(unix int64, length ...int) string
Example
s := TimeUnixToBase36(1705675065)
fmt.Println(s)
s = TimeUnixToBase36(1705675065, 8)
fmt.Println(s)
Output:

s7ijax
00s7ijax

func TimeUnixToFormat added in v1.7.1

func TimeUnixToFormat(unix int64) string
Example
t := TimeUnixToFormat(1705675065)
fmt.Println(t)
Output:

2024-01-19 22:37:45

func UInt16ToBytesArray added in v1.7.1

func UInt16ToBytesArray(i uint16) [2]byte
Example
val := uint16(65535)
bs := UInt16ToBytesArray(val)
fmt.Println(bs)

val /= 2
bs = UInt16ToBytesArray(val)
fmt.Println(bs)

val -= 1
bs = UInt16ToBytesArray(val)
fmt.Println(bs)
Output:

[255 255]
[127 255]
[127 254]

func UInt16ToBytesSlice added in v1.7.1

func UInt16ToBytesSlice(i uint16) []byte
Example
val := uint16(65535)
bs := UInt16ToBytesSlice(val)
fmt.Println(bs)

val /= 2
bs = UInt16ToBytesSlice(val)
fmt.Println(bs)

val -= 1
bs = UInt16ToBytesSlice(val)
fmt.Println(bs)
Output:

[255 255]
[127 255]
[127 254]

func UInt32ToBytesArray added in v1.7.1

func UInt32ToBytesArray(i uint32) [4]byte
Example
val := uint32(4294967295)
bs := UInt32ToBytesArray(val)
fmt.Println(bs)

val = uint32(2147483647)
bs = UInt32ToBytesArray(val)
fmt.Println(bs)

val = uint32(2147417854)
bs = UInt32ToBytesArray(val)
fmt.Println(bs)
Output:

[255 255 255 255]
[127 255 255 255]
[127 254 254 254]

func UInt32ToBytesSlice added in v1.7.1

func UInt32ToBytesSlice(i uint32) []byte
Example
val := uint32(4294967295)
bs := UInt32ToBytesSlice(val)
fmt.Println(bs)

val = uint32(2147483647)
bs = UInt32ToBytesSlice(val)
fmt.Println(bs)

val = uint32(2147417854)
bs = UInt32ToBytesSlice(val)
fmt.Println(bs)
Output:

[255 255 255 255]
[127 255 255 255]
[127 254 254 254]

func UInt64ToBytesArray added in v1.7.1

func UInt64ToBytesArray(i uint64) [8]byte
Example
val := uint64(18446744073709551615)
bs := UInt64ToBytesArray(val)
fmt.Println(bs)

val = uint64(9223372036854775807)
bs = UInt64ToBytesArray(val)
fmt.Println(bs)

val = uint64(9223089458054627070)
bs = UInt64ToBytesArray(val)
fmt.Println(bs)
Output:

[255 255 255 255 255 255 255 255]
[127 255 255 255 255 255 255 255]
[127 254 254 254 254 254 254 254]

func UInt64ToBytesSlice added in v1.7.1

func UInt64ToBytesSlice(i uint64) []byte
Example
val := uint64(18446744073709551615)
bs := UInt64ToBytesSlice(val)
fmt.Println(bs)

val = uint64(9223372036854775807)
bs = UInt64ToBytesSlice(val)
fmt.Println(bs)

val = uint64(9223089458054627070)
bs = UInt64ToBytesSlice(val)
fmt.Println(bs)
Output:

[255 255 255 255 255 255 255 255]
[127 255 255 255 255 255 255 255]
[127 254 254 254 254 254 254 254]

func UIntToBytes

func UIntToBytes(i any) []byte
Example
val8 := uint8(254)
bs := UIntToBytes(val8)
fmt.Println(bs)

val16 := uint16(65534)
bs = UIntToBytes(val16)
fmt.Println(bs)

val32 := uint32(4294967294)
bs = UIntToBytes(val32)
fmt.Println(bs)

val64 := uint64(18446744073709551614)
bs = UIntToBytes(val64)
fmt.Println(bs)

valErr := ""
bs = UIntToBytes(valErr)
fmt.Println(bs)
Output:

[254]
[255 254]
[255 255 255 254]
[255 255 255 255 255 255 255 254]
[]

func Uint32ToIP added in v1.7.1

func Uint32ToIP(i uint32) net.IP

func Uint32ToIPAddr added in v1.7.1

func Uint32ToIPAddr(i uint32) string

func WriteHTTPRespAPIFailed added in v1.7.1

func WriteHTTPRespAPIFailed(w http.ResponseWriter, data any, msg ...any)

func WriteHTTPRespAPIInvalidInput added in v1.7.1

func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, data any, msg ...any)

func WriteHTTPRespAPIInvalidKey added in v1.7.1

func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, data any, msg ...any)

func WriteHTTPRespAPIOk added in v1.7.1

func WriteHTTPRespAPIOk(w http.ResponseWriter, data any, msg ...any)

func WriteHTTPRespAPIProcessingFailed added in v1.7.1

func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, data any, msg ...any)

func YearBetweenTwoDate added in v1.7.1

func YearBetweenTwoDate(t1, t2 time.Time) int64
Example
t1 := int64(1739929126)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(YearBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(YearBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(YearBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2025-02-19 09:38:46 -> 2024-01-18 22:37:45
0
1
-1

func YearBetweenTwoTime added in v1.7.1

func YearBetweenTwoTime(t1, t2 time.Time) int64
Example
t1 := int64(1739929126)
t2 := int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(YearBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0)))
fmt.Println(YearBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(YearBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211064)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(YearBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(YearBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
t1 = int64(1737211066)
t2 = int64(1705588665)
fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2))
fmt.Println(YearBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0)))
fmt.Println(YearBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output:

2025-02-19 09:38:46 -> 2024-01-18 22:37:45
0
1
-1
2025-01-18 22:37:44 -> 2024-01-18 22:37:45
0
0
2025-01-18 22:37:46 -> 2024-01-18 22:37:45
1
-1

Types

type AES added in v1.10.2

type AES struct{}

func NewAES added in v1.10.2

func NewAES() *AES

func (*AES) DecryptCBC added in v1.10.2

func (*AES) DecryptCBC(encrypted, key []byte, iv ...[]byte) *AESResult

func (*AES) EncryptCBC added in v1.10.2

func (*AES) EncryptCBC(origData, key []byte, iv ...[]byte) *AESResult

type AESResult added in v1.10.2

type AESResult struct {
	// contains filtered or unexported fields
}

func NewAESResult added in v1.10.2

func NewAESResult(data []byte, encrypted bool, err error) *AESResult

func (*AESResult) Base64 added in v1.10.2

func (a *AESResult) Base64() *Base64Result

func (*AESResult) Bytes added in v1.10.2

func (a *AESResult) Bytes() []byte

func (*AESResult) Decrypt added in v1.10.2

func (a *AESResult) Decrypt(key []byte, iv ...[]byte) *AESResult

func (*AESResult) Encrypt added in v1.10.2

func (a *AESResult) Encrypt(key []byte, iv ...[]byte) *AESResult

func (*AESResult) Encrypted added in v1.10.2

func (a *AESResult) Encrypted() bool

func (*AESResult) Error added in v1.10.2

func (a *AESResult) Error() error

func (*AESResult) Lower added in v1.10.2

func (a *AESResult) Lower() string

func (*AESResult) String added in v1.10.2

func (a *AESResult) String() string

func (*AESResult) Upper added in v1.10.2

func (a *AESResult) Upper() string

type Base64 added in v1.7.1

type Base64 struct{}

func NewBase64 added in v1.7.1

func NewBase64() *Base64
Example
testString := "Akvicor"
testStringBase64 := "QWt2aWNvcg=="

encodeS := NewBase64().EncodeString(testString)
fmt.Println(encodeS)
encodeB := NewBase64().EncodeBytes([]byte(testString))
fmt.Println(encodeB.String())
decodeS := NewBase64().DecodeString(testStringBase64)
if decodeS.Error() == nil {
	fmt.Println(decodeS)
}
decodeB := NewBase64().DecodeBytes([]byte(testStringBase64))
fmt.Println(decodeB.Bytes())
Output:

QWt2aWNvcg==
QWt2aWNvcg==
Akvicor
[65 107 118 105 99 111 114]

func (*Base64) DecodeBytes added in v1.7.1

func (b *Base64) DecodeBytes(data []byte) *Base64Result

func (*Base64) DecodeString added in v1.7.1

func (b *Base64) DecodeString(str string) *Base64Result

func (*Base64) EncodeBytes added in v1.7.1

func (b *Base64) EncodeBytes(data []byte) *Base64Result

func (*Base64) EncodeString added in v1.7.1

func (b *Base64) EncodeString(str string) *Base64Result

type Base64Result added in v1.7.1

type Base64Result struct {
	// contains filtered or unexported fields
}

func NewBase64Result added in v1.7.1

func NewBase64Result(result string, err error) *Base64Result

func (*Base64Result) Bytes added in v1.7.1

func (b *Base64Result) Bytes() []byte

func (*Base64Result) Error added in v1.7.1

func (b *Base64Result) Error() error

func (*Base64Result) String added in v1.7.1

func (b *Base64Result) String() string

type CRC32 added in v1.7.1

type CRC32 struct{}

func NewCRC32 added in v1.7.1

func NewCRC32() *CRC32
Example
crc := NewCRC32()
res := crc.FromString("Akvicor")
if res.Error() == nil {
	fmt.Println(res.Value())
	fmt.Println(res.Lower())
	fmt.Println(res.Upper())
}
Output:

996205005
3b60e1cd
3B60E1CD

func (*CRC32) FromBytes added in v1.7.1

func (c *CRC32) FromBytes(data []byte) *CRC32Result

func (*CRC32) FromFile added in v1.7.1

func (c *CRC32) FromFile(filename string) *CRC32Result

func (*CRC32) FromFileChunk added in v1.7.1

func (c *CRC32) FromFileChunk(filename string, chunksize int) *CRC32Result

func (*CRC32) FromReader added in v1.7.1

func (c *CRC32) FromReader(r io.Reader) *CRC32Result

func (*CRC32) FromReaderChunk added in v1.7.1

func (c *CRC32) FromReaderChunk(r io.Reader, chunksize int) *CRC32Result

func (*CRC32) FromString added in v1.7.1

func (c *CRC32) FromString(data string) *CRC32Result

type CRC32Pip added in v1.7.1

type CRC32Pip struct {
	// contains filtered or unexported fields
}

func NewCRC32Pip added in v1.7.1

func NewCRC32Pip() *CRC32Pip
Example
cp := NewCRC32Pip()
_, err := io.WriteString(cp, "Akvicor")
if err != nil {
	fmt.Println(err)
}
res := cp.Result()
if res.Error() == nil {
	fmt.Println(res.Array())
	fmt.Println(res.Slice())
}
Output:

[59 96 225 205]
[59 96 225 205]

func (*CRC32Pip) Result added in v1.7.1

func (c *CRC32Pip) Result() *CRC32Result

func (*CRC32Pip) Write added in v1.7.1

func (c *CRC32Pip) Write(data []byte) (n int, err error)

func (*CRC32Pip) WriteBytes added in v1.7.1

func (c *CRC32Pip) WriteBytes(data []byte)

func (*CRC32Pip) WriteString added in v1.7.1

func (c *CRC32Pip) WriteString(data string)

type CRC32Result added in v1.7.1

type CRC32Result struct {
	// contains filtered or unexported fields
}

func NewCRC32Result added in v1.7.1

func NewCRC32Result(result uint32, err error) *CRC32Result

func (*CRC32Result) Array added in v1.7.1

func (c *CRC32Result) Array() [4]byte

func (*CRC32Result) Error added in v1.7.1

func (c *CRC32Result) Error() error

func (*CRC32Result) Lower added in v1.7.1

func (c *CRC32Result) Lower() string

func (*CRC32Result) Slice added in v1.7.1

func (c *CRC32Result) Slice() []byte

func (*CRC32Result) Upper added in v1.7.1

func (c *CRC32Result) Upper() string

func (*CRC32Result) Value added in v1.7.1

func (c *CRC32Result) Value() uint32

type DirListModel added in v1.8.2

type DirListModel struct {
	Files []DirListUnitModel
	Dirs  []DirListUnitModel
	Error error
}

func DirList added in v1.8.2

func DirList(p string) *DirListModel

type DirListUnitModel added in v1.8.2

type DirListUnitModel struct {
	Name    string
	Size    int64
	Mode    fs.FileMode
	ModTime time.Time
}

func NewDirListUnit added in v1.8.2

func NewDirListUnit(name string, size int64, mode fs.FileMode, modeTime time.Time) DirListUnitModel

type FileStatModel added in v1.8.0

type FileStatModel struct {
	// contains filtered or unexported fields
}

func FileStat

func FileStat(filename string) *FileStatModel
Example
if FileStat("testfile").IsDir() {
	fmt.Println("testfile is dir")
}
if FileStat("testfile/testFile1").IsFile() {
	fmt.Println("testfile/testFile1 is file")
}
if FileStat("testfile/testFile2").NotExist() {
	fmt.Println("testfile/testFile2 not exist")
}
Output:

testfile is dir
testfile/testFile1 is file
testfile/testFile2 not exist

func (*FileStatModel) IsDenied added in v1.8.1

func (f *FileStatModel) IsDenied() bool

func (*FileStatModel) IsDir added in v1.8.0

func (f *FileStatModel) IsDir() bool

func (*FileStatModel) IsError added in v1.8.1

func (f *FileStatModel) IsError() bool

func (*FileStatModel) IsExist added in v1.8.0

func (f *FileStatModel) IsExist() bool

func (*FileStatModel) IsFile added in v1.8.0

func (f *FileStatModel) IsFile() bool

func (*FileStatModel) NotDenied added in v1.8.1

func (f *FileStatModel) NotDenied() bool

func (*FileStatModel) NotDir added in v1.8.0

func (f *FileStatModel) NotDir() bool

func (*FileStatModel) NotError added in v1.8.1

func (f *FileStatModel) NotError() bool

func (*FileStatModel) NotExist added in v1.8.0

func (f *FileStatModel) NotExist() bool

func (*FileStatModel) NotFile added in v1.8.0

func (f *FileStatModel) NotFile() bool

type HTTPRespAPIModel added in v1.7.1

type HTTPRespAPIModel struct {
	Code HTTPRespCode `json:"code"`
	Msg  string       `json:"msg"`
	Data any          `json:"data,omitempty"`
}

func NewHTTPResp added in v1.7.1

func NewHTTPResp(code HTTPRespCode, msg string, data any) *HTTPRespAPIModel

NewHTTPResp Util Reserved code range (-100,100)

Example
fmt.Println(NewHTTPResp(HTTPRespCodeOKCode, HTTPRespCodeOKMsg, nil))
Output:

{"code":0,"msg":"ok"}

func ParseHTTPResp added in v1.7.1

func ParseHTTPResp(respstr string) *HTTPRespAPIModel
Example
fmt.Println(ParseHTTPResp(`{"code":0,"msg":"ok"}`).String())
Output:

{"code":0,"msg":"ok"}

func (*HTTPRespAPIModel) Bytes added in v1.10.1

func (r *HTTPRespAPIModel) Bytes() []byte

func (*HTTPRespAPIModel) String added in v1.7.1

func (r *HTTPRespAPIModel) String() string

type HTTPRespCode added in v1.7.1

type HTTPRespCode int

HTTPRespCode Util Reserved code range (-100,100)

type JSON added in v1.7.1

type JSON struct {
	// contains filtered or unexported fields
}

func NewJSON added in v1.7.1

func NewJSON(v any, isArray bool) *JSON
Example
type TestStruct struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}
test1 := TestStruct{
	Name: "Akvicor",
	Age:  17,
}
res := NewJSON(&test1, false)
if res.Error() == nil {
	fmt.Println(res.String())
	fmt.Println(res.Bytes())
	fmt.Println(res.Map())
	fmt.Println(res.Map(0))
	fmt.Println(res.Map(10))
	fmt.Println(res.MapArray())
	fmt.Println(NewJSON(res.Map(), false))
}
test2 := [...]TestStruct{{Name: "Akvicor", Age: 17}, {Name: "MIU", Age: 17}}
res = NewJSON(&test2, true)
if res.Error() == nil {
	fmt.Println(res.Map(1))
	fmt.Println(res.MapArray())
}
Output:

{"name":"Akvicor","age":17}
[123 34 110 97 109 101 34 58 34 65 107 118 105 99 111 114 34 44 34 97 103 101 34 58 49 55 125]
map[age:17 name:Akvicor]
map[age:17 name:Akvicor]
map[age:17 name:Akvicor]
[map[age:17 name:Akvicor]]
{"age":17,"name":"Akvicor"}
map[age:17 name:MIU]
[map[age:17 name:Akvicor] map[age:17 name:MIU]]

func NewJSONResult added in v1.7.1

func NewJSONResult(data []byte) *JSON
Example
fmt.Println(NewJSONResult([]byte(`{"name":"Akvicor","age":17}`)).Map())
fmt.Println(NewJSONResult([]byte(`[{"name":"Akvicor","age":17}]`)).Map())
Output:

map[age:17 name:Akvicor]
map[age:17 name:Akvicor]

func (*JSON) Bytes added in v1.7.1

func (j *JSON) Bytes() []byte

func (*JSON) Error added in v1.7.1

func (j *JSON) Error() error

func (*JSON) Map added in v1.7.1

func (j *JSON) Map(idx ...int) map[string]any

func (*JSON) MapArray added in v1.7.1

func (j *JSON) MapArray() []map[string]any

func (*JSON) String added in v1.7.1

func (j *JSON) String() string

type KeyResult added in v1.10.3

type KeyResult struct {
	// contains filtered or unexported fields
}

func KeyResultFromHexString added in v1.10.3

func KeyResultFromHexString(hx string) *KeyResult

func NewKeyResult added in v1.10.3

func NewKeyResult(data []byte, err error) *KeyResult

func RandomKey added in v1.10.3

func RandomKey(l int) *KeyResult

func (*KeyResult) Bytes added in v1.10.3

func (k *KeyResult) Bytes() []byte

func (*KeyResult) Error added in v1.10.3

func (k *KeyResult) Error() error

func (*KeyResult) Lower added in v1.10.3

func (k *KeyResult) Lower() string

func (*KeyResult) Upper added in v1.10.3

func (k *KeyResult) Upper() string

type MD5 added in v1.7.1

type MD5 struct{}

func NewMD5 added in v1.7.1

func NewMD5() *MD5
Example
m5 := NewMD5()
res := m5.FromString("Akvicor")
if res.Error() == nil {
	fmt.Println(res.Lower())
	fmt.Println(res.Upper())
	fmt.Println(res.Slice())
}
Output:

f812705c26adc52561415189e5f78edb
F812705C26ADC52561415189E5F78EDB
[248 18 112 92 38 173 197 37 97 65 81 137 229 247 142 219]

func (*MD5) FromBytes added in v1.7.1

func (m *MD5) FromBytes(b []byte) *MD5Result

func (*MD5) FromFile added in v1.7.1

func (m *MD5) FromFile(filename string) *MD5Result

func (*MD5) FromFileChunk added in v1.7.1

func (m *MD5) FromFileChunk(filename string, chunksize int) *MD5Result

func (*MD5) FromReader added in v1.7.1

func (m *MD5) FromReader(r io.Reader) *MD5Result

func (*MD5) FromReaderChunk added in v1.7.1

func (m *MD5) FromReaderChunk(r io.Reader, chunksize int) *MD5Result

func (*MD5) FromString added in v1.7.1

func (m *MD5) FromString(str string) *MD5Result

type MD5Pip added in v1.7.1

type MD5Pip struct {
	// contains filtered or unexported fields
}

func NewMD5Pip added in v1.7.1

func NewMD5Pip() *MD5Pip
Example
mp := NewMD5Pip()
_, err := io.WriteString(mp, "Akvicor")
if err != nil {
	fmt.Println(err)
}
res := mp.Result()
if res.Error() == nil {
	fmt.Println(res.Array())
	fmt.Println(res.Slice())
}
Output:

[248 18 112 92 38 173 197 37 97 65 81 137 229 247 142 219]
[248 18 112 92 38 173 197 37 97 65 81 137 229 247 142 219]

func (*MD5Pip) Result added in v1.7.1

func (m *MD5Pip) Result() *MD5Result

func (*MD5Pip) Write added in v1.7.1

func (m *MD5Pip) Write(data []byte) (n int, err error)

func (*MD5Pip) WriteBytes added in v1.7.1

func (m *MD5Pip) WriteBytes(data []byte) error

func (*MD5Pip) WriteString added in v1.7.1

func (m *MD5Pip) WriteString(data string) error

type MD5Result added in v1.7.1

type MD5Result struct {
	// contains filtered or unexported fields
}

func NewMD5Result added in v1.7.1

func NewMD5Result(result []byte, err error) *MD5Result

func (*MD5Result) Array added in v1.7.1

func (m *MD5Result) Array() [MD5ResultLength]byte

func (*MD5Result) Error added in v1.7.1

func (m *MD5Result) Error() error

func (*MD5Result) Lower added in v1.7.1

func (m *MD5Result) Lower() string

func (*MD5Result) Slice added in v1.7.1

func (m *MD5Result) Slice() []byte

func (*MD5Result) Upper added in v1.7.1

func (m *MD5Result) Upper() string

type RemoveDuplicates added in v1.10.2

type RemoveDuplicates struct{}
Example
s := []string{
	"aaa",
	"bbb",
	"aaa",
	"ccc",
	"aaa",
}
ss := NewRemoveDuplicates().String(s)
fmt.Println(ss)
Output:

[aaa bbb ccc]

func NewRemoveDuplicates added in v1.10.2

func NewRemoveDuplicates() *RemoveDuplicates

func (*RemoveDuplicates) Byte added in v1.10.2

func (d *RemoveDuplicates) Byte(s []byte) []byte

func (*RemoveDuplicates) Float32 added in v1.10.2

func (d *RemoveDuplicates) Float32(s []float32) []float32

func (*RemoveDuplicates) Float64 added in v1.10.2

func (d *RemoveDuplicates) Float64(s []float64) []float64

func (*RemoveDuplicates) Int added in v1.10.2

func (d *RemoveDuplicates) Int(s []int) []int

func (*RemoveDuplicates) Int16 added in v1.10.2

func (d *RemoveDuplicates) Int16(s []int16) []int16

func (*RemoveDuplicates) Int32 added in v1.10.2

func (d *RemoveDuplicates) Int32(s []int32) []int32

func (*RemoveDuplicates) Int64 added in v1.10.2

func (d *RemoveDuplicates) Int64(s []int64) []int64

func (*RemoveDuplicates) Int8 added in v1.10.2

func (d *RemoveDuplicates) Int8(s []int8) []int8

func (*RemoveDuplicates) String added in v1.10.2

func (d *RemoveDuplicates) String(s []string) []string

func (*RemoveDuplicates) UInt added in v1.10.2

func (d *RemoveDuplicates) UInt(s []uint) []uint

func (*RemoveDuplicates) UInt16 added in v1.10.2

func (d *RemoveDuplicates) UInt16(s []uint16) []uint16

func (*RemoveDuplicates) UInt32 added in v1.10.2

func (d *RemoveDuplicates) UInt32(s []uint32) []uint32

func (*RemoveDuplicates) UInt64 added in v1.10.2

func (d *RemoveDuplicates) UInt64(s []uint64) []uint64

func (*RemoveDuplicates) UInt8 added in v1.10.2

func (d *RemoveDuplicates) UInt8(s []uint8) []uint8

type SHA1 added in v1.7.1

type SHA1 struct{}

func NewSHA1 added in v1.7.1

func NewSHA1() *SHA1
Example
s := NewSHA1()
res := s.FromString("Akvicor")
if res.Error() == nil {
	fmt.Println(res.Lower())
	fmt.Println(res.Upper())
	fmt.Println(res.Slice())
}
Output:

49296886bfedac0dd0399030bc0dbe12e5eed489
49296886BFEDAC0DD0399030BC0DBE12E5EED489
[73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137]

func (*SHA1) FromBytes added in v1.7.1

func (s *SHA1) FromBytes(b []byte) *SHA1Result

func (*SHA1) FromFile added in v1.7.1

func (s *SHA1) FromFile(filename string) *SHA1Result

func (*SHA1) FromFileChunk added in v1.7.1

func (s *SHA1) FromFileChunk(filename string, chunksize int) *SHA1Result

func (*SHA1) FromReader added in v1.7.1

func (s *SHA1) FromReader(r io.Reader) *SHA1Result

func (*SHA1) FromReaderChunk added in v1.7.1

func (s *SHA1) FromReaderChunk(r io.Reader, chunksize int) *SHA1Result

func (*SHA1) FromString added in v1.7.1

func (s *SHA1) FromString(str string) *SHA1Result

type SHA1Pip added in v1.7.1

type SHA1Pip struct {
	// contains filtered or unexported fields
}

func NewSHA1Pip added in v1.7.1

func NewSHA1Pip() *SHA1Pip
Example
sp := NewSHA1Pip()
_, err := io.WriteString(sp, "Akvicor")
if err != nil {
	fmt.Println(err)
}
res := sp.Result()
if res.Error() == nil {
	fmt.Println(res.Array())
	fmt.Println(res.Slice())
}
Output:

[73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137]
[73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137]

func (*SHA1Pip) Result added in v1.7.1

func (s *SHA1Pip) Result() *SHA1Result

func (*SHA1Pip) Write added in v1.7.1

func (s *SHA1Pip) Write(data []byte) (n int, err error)

func (*SHA1Pip) WriteBytes added in v1.7.1

func (s *SHA1Pip) WriteBytes(data []byte) error

func (*SHA1Pip) WriteString added in v1.7.1

func (s *SHA1Pip) WriteString(data string) error

type SHA1Result added in v1.7.1

type SHA1Result struct {
	// contains filtered or unexported fields
}

func NewSHA1Result added in v1.7.1

func NewSHA1Result(result []byte, err error) *SHA1Result

func (*SHA1Result) Array added in v1.7.1

func (s *SHA1Result) Array() [SHA1ResultLength]byte

func (*SHA1Result) Error added in v1.7.1

func (s *SHA1Result) Error() error

func (*SHA1Result) Lower added in v1.7.1

func (s *SHA1Result) Lower() string

func (*SHA1Result) Slice added in v1.7.1

func (s *SHA1Result) Slice() []byte

func (*SHA1Result) Upper added in v1.7.1

func (s *SHA1Result) Upper() string

type SHA256 added in v1.7.1

type SHA256 struct{}

func NewSHA256 added in v1.7.1

func NewSHA256() *SHA256
Example
s := NewSHA256()
res := s.FromString("Akvicor")
if res.Error() == nil {
	fmt.Println(res.Lower())
	fmt.Println(res.Upper())
	fmt.Println(res.Slice())
}
Output:

36acc0924a190c77386cd819a3bff60251345e8654399f68e8b740a1afa62ff5
36ACC0924A190C77386CD819A3BFF60251345E8654399F68E8B740A1AFA62FF5
[54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245]

func (*SHA256) FromBytes added in v1.7.1

func (s *SHA256) FromBytes(b []byte) *SHA256Result

func (*SHA256) FromFile added in v1.7.1

func (s *SHA256) FromFile(filename string) *SHA256Result

func (*SHA256) FromFileChunk added in v1.7.1

func (s *SHA256) FromFileChunk(filename string, chunksize int) *SHA256Result

func (*SHA256) FromReader added in v1.7.1

func (s *SHA256) FromReader(r io.Reader) *SHA256Result

func (*SHA256) FromReaderChunk added in v1.7.1

func (s *SHA256) FromReaderChunk(r io.Reader, chunksize int) *SHA256Result

func (*SHA256) FromString added in v1.7.1

func (s *SHA256) FromString(str string) *SHA256Result

type SHA256Pip added in v1.7.1

type SHA256Pip struct {
	// contains filtered or unexported fields
}

func NewSHA256Pip added in v1.7.1

func NewSHA256Pip() *SHA256Pip
Example
sp := NewSHA256Pip()
_, err := io.WriteString(sp, "Akvicor")
if err != nil {
	fmt.Println(err)
}
res := sp.Result()
if res.Error() == nil {
	fmt.Println(res.Array())
	fmt.Println(res.Slice())
}
Output:

[54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245]
[54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245]

func (*SHA256Pip) Result added in v1.7.1

func (s *SHA256Pip) Result() *SHA256Result

func (*SHA256Pip) Write added in v1.7.1

func (s *SHA256Pip) Write(data []byte) (n int, err error)

func (*SHA256Pip) WriteBytes added in v1.7.1

func (s *SHA256Pip) WriteBytes(data []byte) error

func (*SHA256Pip) WriteString added in v1.7.1

func (s *SHA256Pip) WriteString(data string) error

type SHA256Result added in v1.7.1

type SHA256Result struct {
	// contains filtered or unexported fields
}

func NewSHA256Result added in v1.7.1

func NewSHA256Result(result []byte, err error) *SHA256Result

func (*SHA256Result) Array added in v1.7.1

func (s *SHA256Result) Array() [SHA256ResultLength]byte

func (*SHA256Result) Error added in v1.7.1

func (s *SHA256Result) Error() error

func (*SHA256Result) Lower added in v1.7.1

func (s *SHA256Result) Lower() string

func (*SHA256Result) Slice added in v1.7.1

func (s *SHA256Result) Slice() []byte

func (*SHA256Result) Upper added in v1.7.1

func (s *SHA256Result) Upper() string

type SHA512 added in v1.7.1

type SHA512 struct{}

func NewSHA512 added in v1.7.1

func NewSHA512() *SHA512
Example
s := NewSHA512()
res := s.FromString("Akvicor")
if res.Error() == nil {
	fmt.Println(res.Lower())
	fmt.Println(res.Upper())
	fmt.Println(res.Slice())
}
Output:

6fdfb481af6573ac49d4031d22f0d73f0f24ea8cb113982593ec65ab085b0635b46d7683aa3f4ef36c2cb25a7bb8ba8cbae2fa3e9810d35b1c70a93f37586361
6FDFB481AF6573AC49D4031D22F0D73F0F24EA8CB113982593EC65AB085B0635B46D7683AA3F4EF36C2CB25A7BB8BA8CBAE2FA3E9810D35B1C70A93F37586361
[111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97]

func (*SHA512) FromBytes added in v1.7.1

func (s *SHA512) FromBytes(b []byte) *SHA512Result

func (*SHA512) FromFile added in v1.7.1

func (s *SHA512) FromFile(filename string) *SHA512Result

func (*SHA512) FromFileChunk added in v1.7.1

func (s *SHA512) FromFileChunk(filename string, chunksize int) *SHA512Result

func (*SHA512) FromReader added in v1.7.1

func (s *SHA512) FromReader(r io.Reader) *SHA512Result

func (*SHA512) FromReaderChunk added in v1.7.1

func (s *SHA512) FromReaderChunk(r io.Reader, chunksize int) *SHA512Result

func (*SHA512) FromString added in v1.7.1

func (s *SHA512) FromString(str string) *SHA512Result

type SHA512Pip added in v1.7.1

type SHA512Pip struct {
	// contains filtered or unexported fields
}

func NewSHA512Pip added in v1.7.1

func NewSHA512Pip() *SHA512Pip
Example
sp := NewSHA512Pip()
_, err := io.WriteString(sp, "Akvicor")
if err != nil {
	fmt.Println(err)
}
res := sp.Result()
if res.Error() == nil {
	fmt.Println(res.Array())
	fmt.Println(res.Slice())
}
Output:

[111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97]
[111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97]

func (*SHA512Pip) Result added in v1.7.1

func (s *SHA512Pip) Result() *SHA512Result

func (*SHA512Pip) Write added in v1.7.1

func (s *SHA512Pip) Write(data []byte) (n int, err error)

func (*SHA512Pip) WriteBytes added in v1.7.1

func (s *SHA512Pip) WriteBytes(data []byte) error

func (*SHA512Pip) WriteString added in v1.7.1

func (s *SHA512Pip) WriteString(data string) error

type SHA512Result added in v1.7.1

type SHA512Result struct {
	// contains filtered or unexported fields
}

func NewSHA512Result added in v1.7.1

func NewSHA512Result(result []byte, err error) *SHA512Result

func (*SHA512Result) Array added in v1.7.1

func (s *SHA512Result) Array() [SHA512ResultLength]byte

func (*SHA512Result) Error added in v1.7.1

func (s *SHA512Result) Error() error

func (*SHA512Result) Lower added in v1.7.1

func (s *SHA512Result) Lower() string

func (*SHA512Result) Slice added in v1.7.1

func (s *SHA512Result) Slice() []byte

func (*SHA512Result) Upper added in v1.7.1

func (s *SHA512Result) Upper() string

type Size added in v1.8.2

type Size uint64
const SizeB Size = 1
const SizeByte Size = 1

func (Size) B added in v1.8.2

func (s Size) B() *SizeFormatModel

B return size in B

func (Size) E added in v1.8.2

func (s Size) E() *SizeFormatModel

E return size in E

func (Size) EB added in v1.8.2

func (s Size) EB() *SizeFormatModel

EB return size in EB

func (Size) EiB added in v1.8.2

func (s Size) EiB() *SizeFormatModel

EiB return size in EiB

func (Size) Format added in v1.8.2

func (s Size) Format(sep string, binaryPrefixes bool) string

Format size

use sep to separate each unit

func (Size) FormatSlice added in v1.8.2

func (s Size) FormatSlice(binaryPrefixes bool) []*SizeFormatModel

FormatSlice format size

each unit is stored in a separate SizeFormatModel

func (Size) G added in v1.8.2

func (s Size) G() *SizeFormatModel

G return size in G

func (Size) GB added in v1.8.2

func (s Size) GB() *SizeFormatModel

GB return size in GB

func (Size) GiB added in v1.8.2

func (s Size) GiB() *SizeFormatModel

GiB return size in GiB

func (Size) HighestUnit added in v1.8.2

func (s Size) HighestUnit(binaryPrefixes bool) *SizeFormatModel

HighestUnit return the highest unit value

func (Size) K added in v1.8.2

func (s Size) K() *SizeFormatModel

K return size in K

func (Size) KB added in v1.8.2

func (s Size) KB() *SizeFormatModel

KB return size in KB

func (Size) KiB added in v1.8.2

func (s Size) KiB() *SizeFormatModel

KiB return size in KiB

func (Size) M added in v1.8.2

func (s Size) M() *SizeFormatModel

M return size in M

func (Size) MB added in v1.8.2

func (s Size) MB() *SizeFormatModel

MB return size in MB

func (Size) MiB added in v1.8.2

func (s Size) MiB() *SizeFormatModel

MiB return size in MiB

func (Size) P added in v1.8.2

func (s Size) P() *SizeFormatModel

P return size in P

func (Size) PB added in v1.8.2

func (s Size) PB() *SizeFormatModel

PB return size in PB

func (Size) PiB added in v1.8.2

func (s Size) PiB() *SizeFormatModel

PiB return size in PiB

func (Size) String added in v1.8.2

func (s Size) String() string

func (Size) T added in v1.8.2

func (s Size) T() *SizeFormatModel

T return size in T

func (Size) TB added in v1.8.2

func (s Size) TB() *SizeFormatModel

TB return size in TB

func (Size) TiB added in v1.8.2

func (s Size) TiB() *SizeFormatModel

TiB return size in TiB

type SizeFormatModel added in v1.8.2

type SizeFormatModel struct {
	// size value in uint64
	Value uint64
	// size value in float64
	ValueFloat float64
	// size unit symbol
	Symbol string
}

SizeFormatModel save calculation result with uint64 and float64

func (*SizeFormatModel) Format added in v1.8.2

func (f *SizeFormatModel) Format(length int, sep string, zeroPadding bool) string

Format return formatted string of specified length

use sep to separate number and symbol
use zeroPadding to determine whether to pad the number with 0

func (*SizeFormatModel) FormatFloat added in v1.8.2

func (f *SizeFormatModel) FormatFloat(length int, precision int, sep string, zeroPadding bool) string

FormatFloat return formatted string of specified length

use precision to preserve number precision
use sep to separate number and symbol
use zeroPadding to determine whether to pad the number with 0

func (*SizeFormatModel) FormatValue added in v1.8.2

func (f *SizeFormatModel) FormatValue(valueLength int, sep string, zeroPadding bool) string

FormatValue return formatted string of specified length of value

use sep to separate number and symbol
use zeroPadding to determine whether to pad the number with 0

func (*SizeFormatModel) FormatValueFloat added in v1.8.2

func (f *SizeFormatModel) FormatValueFloat(valueLength int, precision int, sep string, zeroPadding bool) string

FormatValueFloat return formatted string of specified length of value

use precision to preserve number precision
use sep to separate number and symbol
use zeroPadding to determine whether to pad the number with 0

func (*SizeFormatModel) SingleSymbol added in v1.8.2

func (f *SizeFormatModel) SingleSymbol() *SizeFormatModel

SingleSymbol convert symbol to single character

func (*SizeFormatModel) Size added in v1.8.2

func (f *SizeFormatModel) Size() Size

Size calculate original Size

func (*SizeFormatModel) SizeFloat added in v1.8.2

func (f *SizeFormatModel) SizeFloat() Size

SizeFloat calculate original Size

due to precision, it is not guaranteed to restore the original Size

func (*SizeFormatModel) String added in v1.8.2

func (f *SizeFormatModel) String() string

func (*SizeFormatModel) StringFloat added in v1.8.2

func (f *SizeFormatModel) StringFloat() string

Jump to

Keyboard shortcuts

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