Documentation ¶
Index ¶
- Constants
- Variables
- func BitSet(b any, bit byte, set bool)
- func BytesArrayToUInt16(buf [2]byte) uint16
- func BytesArrayToUInt32(buf [4]byte) uint32
- func BytesArrayToUInt64(buf [8]byte) uint64
- func BytesCombine(pBytes ...[]byte) []byte
- func BytesSliceToUInt16(buf []byte) uint16
- func BytesSliceToUInt32(buf []byte) uint32
- func BytesSliceToUInt64(buf []byte) uint64
- func BytesToUInt(buf []byte) uint64
- func DayBetweenTwoDate(t1, t2 time.Time) int64
- func DayBetweenTwoTime(t1, t2 time.Time) int64
- func DirSize(p string) (int64, error)
- func GetAvailablePort() (int, error)
- func GetClientIP(r *http.Request) string
- func GetClientPublicIP(r *http.Request) string
- func GetLocalIp() (string, error)
- func HourBetweenTwoTime(t1, t2 time.Time) int64
- func HttpGet(u string, args any, contentType string, header map[string]string) ([]byte, error)
- func HttpPost(u string, args any, contentType string, header map[string]string) ([]byte, error)
- func HttpPostGet(u string, argsGET, argsPOST any, contentType string, header map[string]string) ([]byte, error)
- func IPAddrToUint32(ip string) (uint32, error)
- func IPToUint32(ip net.IP) (uint32, error)
- func IsIPAddr(ip string) bool
- func IsLocalIP(ip net.IP) bool
- func IsLocalIPAddr(ip string) bool
- func LastPage(w http.ResponseWriter, r *http.Request)
- func MinuteBetweenTwoTime(t1, t2 time.Time) int64
- func MkdirP(p string, perm ...os.FileMode) error
- func MonthBetweenTwoDate(t1, t2 time.Time) int64
- func MonthBetweenTwoTime(t1, t2 time.Time) int64
- func ParseRandomStringWithTimestamp(str string) (int64, string)
- func RandomString(length int, str ...string) string
- func RandomStringAtLeastOnce(length int, str ...string) string
- func RandomStringWithTimestamp(length int, unix ...int64) string
- func Reload(w http.ResponseWriter, r *http.Request)
- func RemoteIP(r *http.Request) string
- func RespRedirect(w http.ResponseWriter, r *http.Request, url string)
- func SecondBetweenTwoTime(t1, t2 time.Time) int64
- func SplitPath(p string) (head, tail string)
- func SplitPathRepeat(p string, repeat int) (head, tail string)
- func SplitPathSkip(p string, skip int) (head, tail string)
- func TcpPortIsOpen(ip, port string) bool
- func TcpPortIsOpenByAddr(ipPort string) bool
- func TimeBase36ToUnix(t string) int64
- func TimeNowFormat() string
- func TimeNowToBase36(length ...int) string
- func TimeUnixToBase36(unix int64, length ...int) string
- func TimeUnixToFormat(unix int64) string
- func UInt16ToBytesArray(i uint16) [2]byte
- func UInt16ToBytesSlice(i uint16) []byte
- func UInt32ToBytesArray(i uint32) [4]byte
- func UInt32ToBytesSlice(i uint32) []byte
- func UInt64ToBytesArray(i uint64) [8]byte
- func UInt64ToBytesSlice(i uint64) []byte
- func UIntToBytes(i any) []byte
- func Uint32ToIP(i uint32) net.IP
- func Uint32ToIPAddr(i uint32) string
- func WriteHTTPRespAPIFailed(w http.ResponseWriter, data any, msg ...any)
- func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, data any, msg ...any)
- func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, data any, msg ...any)
- func WriteHTTPRespAPIOk(w http.ResponseWriter, data any, msg ...any)
- func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, data any, msg ...any)
- func YearBetweenTwoDate(t1, t2 time.Time) int64
- func YearBetweenTwoTime(t1, t2 time.Time) int64
- type AES
- type AESResult
- func (a *AESResult) Base64() *Base64Result
- func (a *AESResult) Bytes() []byte
- func (a *AESResult) Decrypt(key []byte, iv ...[]byte) *AESResult
- func (a *AESResult) Encrypt(key []byte, iv ...[]byte) *AESResult
- func (a *AESResult) Encrypted() bool
- func (a *AESResult) Error() error
- func (a *AESResult) Lower() string
- func (a *AESResult) String() string
- func (a *AESResult) Upper() string
- type Base64
- type Base64Result
- type CRC32
- func (c *CRC32) FromBytes(data []byte) *CRC32Result
- func (c *CRC32) FromFile(filename string) *CRC32Result
- func (c *CRC32) FromFileChunk(filename string, chunksize int) *CRC32Result
- func (c *CRC32) FromReader(r io.Reader) *CRC32Result
- func (c *CRC32) FromReaderChunk(r io.Reader, chunksize int) *CRC32Result
- func (c *CRC32) FromString(data string) *CRC32Result
- type CRC32Pip
- type CRC32Result
- type DirListModel
- type DirListUnitModel
- type FileStatModel
- func (f *FileStatModel) IsDenied() bool
- func (f *FileStatModel) IsDir() bool
- func (f *FileStatModel) IsError() bool
- func (f *FileStatModel) IsExist() bool
- func (f *FileStatModel) IsFile() bool
- func (f *FileStatModel) NotDenied() bool
- func (f *FileStatModel) NotDir() bool
- func (f *FileStatModel) NotError() bool
- func (f *FileStatModel) NotExist() bool
- func (f *FileStatModel) NotFile() bool
- type HTTPRespAPIModel
- type HTTPRespCode
- type JSON
- type KeyResult
- type MD5
- func (m *MD5) FromBytes(b []byte) *MD5Result
- func (m *MD5) FromFile(filename string) *MD5Result
- func (m *MD5) FromFileChunk(filename string, chunksize int) *MD5Result
- func (m *MD5) FromReader(r io.Reader) *MD5Result
- func (m *MD5) FromReaderChunk(r io.Reader, chunksize int) *MD5Result
- func (m *MD5) FromString(str string) *MD5Result
- type MD5Pip
- type MD5Result
- type RemoveDuplicates
- func (d *RemoveDuplicates) Byte(s []byte) []byte
- func (d *RemoveDuplicates) Float32(s []float32) []float32
- func (d *RemoveDuplicates) Float64(s []float64) []float64
- func (d *RemoveDuplicates) Int(s []int) []int
- func (d *RemoveDuplicates) Int16(s []int16) []int16
- func (d *RemoveDuplicates) Int32(s []int32) []int32
- func (d *RemoveDuplicates) Int64(s []int64) []int64
- func (d *RemoveDuplicates) Int8(s []int8) []int8
- func (d *RemoveDuplicates) String(s []string) []string
- func (d *RemoveDuplicates) UInt(s []uint) []uint
- func (d *RemoveDuplicates) UInt16(s []uint16) []uint16
- func (d *RemoveDuplicates) UInt32(s []uint32) []uint32
- func (d *RemoveDuplicates) UInt64(s []uint64) []uint64
- func (d *RemoveDuplicates) UInt8(s []uint8) []uint8
- type SHA1
- func (s *SHA1) FromBytes(b []byte) *SHA1Result
- func (s *SHA1) FromFile(filename string) *SHA1Result
- func (s *SHA1) FromFileChunk(filename string, chunksize int) *SHA1Result
- func (s *SHA1) FromReader(r io.Reader) *SHA1Result
- func (s *SHA1) FromReaderChunk(r io.Reader, chunksize int) *SHA1Result
- func (s *SHA1) FromString(str string) *SHA1Result
- type SHA1Pip
- type SHA1Result
- type SHA256
- func (s *SHA256) FromBytes(b []byte) *SHA256Result
- func (s *SHA256) FromFile(filename string) *SHA256Result
- func (s *SHA256) FromFileChunk(filename string, chunksize int) *SHA256Result
- func (s *SHA256) FromReader(r io.Reader) *SHA256Result
- func (s *SHA256) FromReaderChunk(r io.Reader, chunksize int) *SHA256Result
- func (s *SHA256) FromString(str string) *SHA256Result
- type SHA256Pip
- type SHA256Result
- type SHA512
- func (s *SHA512) FromBytes(b []byte) *SHA512Result
- func (s *SHA512) FromFile(filename string) *SHA512Result
- func (s *SHA512) FromFileChunk(filename string, chunksize int) *SHA512Result
- func (s *SHA512) FromReader(r io.Reader) *SHA512Result
- func (s *SHA512) FromReaderChunk(r io.Reader, chunksize int) *SHA512Result
- func (s *SHA512) FromString(str string) *SHA512Result
- type SHA512Pip
- type SHA512Result
- type Size
- func (s Size) B() *SizeFormatModel
- func (s Size) E() *SizeFormatModel
- func (s Size) EB() *SizeFormatModel
- func (s Size) EiB() *SizeFormatModel
- func (s Size) Format(sep string, binaryPrefixes bool) string
- func (s Size) FormatSlice(binaryPrefixes bool) []*SizeFormatModel
- func (s Size) G() *SizeFormatModel
- func (s Size) GB() *SizeFormatModel
- func (s Size) GiB() *SizeFormatModel
- func (s Size) HighestUnit(binaryPrefixes bool) *SizeFormatModel
- func (s Size) K() *SizeFormatModel
- func (s Size) KB() *SizeFormatModel
- func (s Size) KiB() *SizeFormatModel
- func (s Size) M() *SizeFormatModel
- func (s Size) MB() *SizeFormatModel
- func (s Size) MiB() *SizeFormatModel
- func (s Size) P() *SizeFormatModel
- func (s Size) PB() *SizeFormatModel
- func (s Size) PiB() *SizeFormatModel
- func (s Size) String() string
- func (s Size) T() *SizeFormatModel
- func (s Size) TB() *SizeFormatModel
- func (s Size) TiB() *SizeFormatModel
- type SizeFormatModel
- func (f *SizeFormatModel) Format(length int, sep string, zeroPadding bool) string
- func (f *SizeFormatModel) FormatFloat(length int, precision int, sep string, zeroPadding bool) string
- func (f *SizeFormatModel) FormatValue(valueLength int, sep string, zeroPadding bool) string
- func (f *SizeFormatModel) FormatValueFloat(valueLength int, precision int, sep string, zeroPadding bool) string
- func (f *SizeFormatModel) SingleSymbol() *SizeFormatModel
- func (f *SizeFormatModel) Size() Size
- func (f *SizeFormatModel) SizeFloat() Size
- func (f *SizeFormatModel) String() string
- func (f *SizeFormatModel) StringFloat() string
Examples ¶
- BitSet
- BytesArrayToUInt16
- BytesArrayToUInt32
- BytesArrayToUInt64
- BytesCombine
- BytesSliceToUInt16
- BytesSliceToUInt32
- BytesSliceToUInt64
- BytesToUInt
- DayBetweenTwoDate
- DayBetweenTwoTime
- DirSize
- FileStat
- GetAvailablePort
- GetLocalIp
- HourBetweenTwoTime
- HttpGet
- HttpPost
- HttpPostGet
- MinuteBetweenTwoTime
- MkdirP
- MonthBetweenTwoDate
- MonthBetweenTwoTime
- NewBase64
- NewCRC32
- NewCRC32Pip
- NewHTTPResp
- NewJSON
- NewJSONResult
- NewMD5
- NewMD5Pip
- NewSHA1
- NewSHA1Pip
- NewSHA256
- NewSHA256Pip
- NewSHA512
- NewSHA512Pip
- ParseHTTPResp
- RandomString
- RandomStringAtLeastOnce
- RandomStringWithTimestamp
- RemoveDuplicates
- SecondBetweenTwoTime
- SplitPath
- SplitPathRepeat
- SplitPathSkip
- TcpPortIsOpen
- TcpPortIsOpenByAddr
- TimeBase36ToUnix
- TimeNowFormat
- TimeNowToBase36
- TimeUnixToBase36
- TimeUnixToFormat
- UInt16ToBytesArray
- UInt16ToBytesSlice
- UInt32ToBytesArray
- UInt32ToBytesSlice
- UInt64ToBytesArray
- UInt64ToBytesSlice
- UIntToBytes
- YearBetweenTwoDate
- YearBetweenTwoTime
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 RandomAll = RandomAlpha + RandomDigit + RandomSpecial
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")
View Source
var RandomSlice = []string{RandomLower, RandomUpper, RandomDigit, RandomSpecial}
Functions ¶
func BitSet ¶
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.3
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.3
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.3
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 ¶
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.3
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.3
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.3
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 ¶
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.3
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.3
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.3
Example ¶
p, err := DirSize("./testfile") if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func GetAvailablePort ¶ added in v1.10.3
Example ¶
p, err := GetAvailablePort() if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func GetClientIP ¶ added in v1.7.3
func GetClientPublicIP ¶ added in v1.7.3
func GetLocalIp ¶ added in v1.10.3
Example ¶
p, err := GetLocalIp() if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func HourBetweenTwoTime ¶ added in v1.7.3
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.3
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.3
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.3
func HttpPostGet(u string, argsGET, argsPOST any, contentType string, header map[string]string) ([]byte, error)
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.3
func IsLocalIPAddr ¶ added in v1.7.3
func MinuteBetweenTwoTime ¶ added in v1.7.3
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.3
Example ¶
err := MkdirP("testfile/testfile") if err != nil { fmt.Println(err) }
Output:
func MonthBetweenTwoDate ¶ added in v1.7.3
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.3
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 ¶ added in v1.4.0
func RandomString ¶ added in v1.3.0
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.3
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 ¶ added in v1.3.0
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 RespRedirect ¶ added in v1.7.3
func RespRedirect(w http.ResponseWriter, r *http.Request, url string)
func SecondBetweenTwoTime ¶ added in v1.7.3
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 ¶ added in v1.3.0
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 ¶ added in v1.6.0
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 ¶ added in v1.5.0
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.3
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.3
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.3
Example ¶
t := TimeBase36ToUnix("s7ijax") fmt.Println(t) t = TimeBase36ToUnix("00s7ijax") fmt.Println(t)
Output: 1705675065 1705675065
func TimeNowFormat ¶ added in v1.7.3
func TimeNowFormat() string
Example ¶
t := TimeNowFormat() if len(t) != 19 { fmt.Println(t) }
Output:
func TimeNowToBase36 ¶ added in v1.7.3
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.3
Example ¶
s := TimeUnixToBase36(1705675065) fmt.Println(s) s = TimeUnixToBase36(1705675065, 8) fmt.Println(s)
Output: s7ijax 00s7ijax
func TimeUnixToFormat ¶ added in v1.7.3
Example ¶
t := TimeUnixToFormat(1705675065) fmt.Println(t)
Output: 2024-01-19 22:37:45
func UInt16ToBytesArray ¶ added in v1.7.3
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.3
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.3
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.3
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.3
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.3
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 ¶
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.3
func Uint32ToIPAddr ¶ added in v1.7.3
func WriteHTTPRespAPIFailed ¶ added in v1.7.3
func WriteHTTPRespAPIFailed(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIInvalidInput ¶ added in v1.7.3
func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIInvalidKey ¶ added in v1.7.3
func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIOk ¶ added in v1.7.3
func WriteHTTPRespAPIOk(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIProcessingFailed ¶ added in v1.7.3
func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, data any, msg ...any)
func YearBetweenTwoDate ¶ added in v1.7.3
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.3
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 AESResult ¶ added in v1.10.3
type AESResult struct {
// contains filtered or unexported fields
}
func NewAESResult ¶ added in v1.10.3
func (*AESResult) Base64 ¶ added in v1.10.3
func (a *AESResult) Base64() *Base64Result
type Base64 ¶ added in v1.7.3
type Base64 struct{}
func NewBase64 ¶ added in v1.7.3
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.3
func (b *Base64) DecodeBytes(data []byte) *Base64Result
func (*Base64) DecodeString ¶ added in v1.7.3
func (b *Base64) DecodeString(str string) *Base64Result
func (*Base64) EncodeBytes ¶ added in v1.7.3
func (b *Base64) EncodeBytes(data []byte) *Base64Result
func (*Base64) EncodeString ¶ added in v1.7.3
func (b *Base64) EncodeString(str string) *Base64Result
type Base64Result ¶ added in v1.7.3
type Base64Result struct {
// contains filtered or unexported fields
}
func NewBase64Result ¶ added in v1.7.3
func NewBase64Result(result string, err error) *Base64Result
func (*Base64Result) Bytes ¶ added in v1.7.3
func (b *Base64Result) Bytes() []byte
func (*Base64Result) Error ¶ added in v1.7.3
func (b *Base64Result) Error() error
func (*Base64Result) String ¶ added in v1.7.3
func (b *Base64Result) String() string
type CRC32 ¶ added in v1.7.3
type CRC32 struct{}
func NewCRC32 ¶ added in v1.7.3
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.3
func (c *CRC32) FromBytes(data []byte) *CRC32Result
func (*CRC32) FromFile ¶ added in v1.7.3
func (c *CRC32) FromFile(filename string) *CRC32Result
func (*CRC32) FromFileChunk ¶ added in v1.7.3
func (c *CRC32) FromFileChunk(filename string, chunksize int) *CRC32Result
func (*CRC32) FromReader ¶ added in v1.7.3
func (c *CRC32) FromReader(r io.Reader) *CRC32Result
func (*CRC32) FromReaderChunk ¶ added in v1.7.3
func (c *CRC32) FromReaderChunk(r io.Reader, chunksize int) *CRC32Result
func (*CRC32) FromString ¶ added in v1.7.3
func (c *CRC32) FromString(data string) *CRC32Result
type CRC32Pip ¶ added in v1.7.3
type CRC32Pip struct {
// contains filtered or unexported fields
}
func NewCRC32Pip ¶ added in v1.7.3
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.3
func (c *CRC32Pip) Result() *CRC32Result
func (*CRC32Pip) WriteBytes ¶ added in v1.7.3
func (*CRC32Pip) WriteString ¶ added in v1.7.3
type CRC32Result ¶ added in v1.7.3
type CRC32Result struct {
// contains filtered or unexported fields
}
func NewCRC32Result ¶ added in v1.7.3
func NewCRC32Result(result uint32, err error) *CRC32Result
func (*CRC32Result) Array ¶ added in v1.7.3
func (c *CRC32Result) Array() [4]byte
func (*CRC32Result) Error ¶ added in v1.7.3
func (c *CRC32Result) Error() error
func (*CRC32Result) Lower ¶ added in v1.7.3
func (c *CRC32Result) Lower() string
func (*CRC32Result) Slice ¶ added in v1.7.3
func (c *CRC32Result) Slice() []byte
func (*CRC32Result) Upper ¶ added in v1.7.3
func (c *CRC32Result) Upper() string
func (*CRC32Result) Value ¶ added in v1.7.3
func (c *CRC32Result) Value() uint32
type DirListModel ¶ added in v1.10.3
type DirListModel struct { Files []DirListUnitModel Dirs []DirListUnitModel Error error }
func DirList ¶ added in v1.10.3
func DirList(p string) *DirListModel
type DirListUnitModel ¶ added in v1.10.3
func NewDirListUnit ¶ added in v1.10.3
type FileStatModel ¶ added in v1.10.3
type FileStatModel struct {
// contains filtered or unexported fields
}
func FileStat ¶ added in v1.2.0
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.10.3
func (f *FileStatModel) IsDenied() bool
func (*FileStatModel) IsDir ¶ added in v1.10.3
func (f *FileStatModel) IsDir() bool
func (*FileStatModel) IsError ¶ added in v1.10.3
func (f *FileStatModel) IsError() bool
func (*FileStatModel) IsExist ¶ added in v1.10.3
func (f *FileStatModel) IsExist() bool
func (*FileStatModel) IsFile ¶ added in v1.10.3
func (f *FileStatModel) IsFile() bool
func (*FileStatModel) NotDenied ¶ added in v1.10.3
func (f *FileStatModel) NotDenied() bool
func (*FileStatModel) NotDir ¶ added in v1.10.3
func (f *FileStatModel) NotDir() bool
func (*FileStatModel) NotError ¶ added in v1.10.3
func (f *FileStatModel) NotError() bool
func (*FileStatModel) NotExist ¶ added in v1.10.3
func (f *FileStatModel) NotExist() bool
func (*FileStatModel) NotFile ¶ added in v1.10.3
func (f *FileStatModel) NotFile() bool
type HTTPRespAPIModel ¶ added in v1.7.3
type HTTPRespAPIModel struct { Code HTTPRespCode `json:"code"` Msg string `json:"msg"` Data any `json:"data,omitempty"` }
func NewHTTPResp ¶ added in v1.7.3
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.3
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.3
func (r *HTTPRespAPIModel) Bytes() []byte
func (*HTTPRespAPIModel) String ¶ added in v1.7.3
func (r *HTTPRespAPIModel) String() string
type HTTPRespCode ¶ added in v1.7.3
type HTTPRespCode int
HTTPRespCode Util Reserved code range (-100,100)
type JSON ¶ added in v1.7.3
type JSON struct {
// contains filtered or unexported fields
}
func NewJSON ¶ added in v1.7.3
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.3
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]
type KeyResult ¶ added in v1.10.3
type KeyResult struct {
// contains filtered or unexported fields
}
func KeyResultFromHexString ¶ added in v1.10.3
func NewKeyResult ¶ added in v1.10.3
type MD5 ¶ added in v1.7.3
type MD5 struct{}
func NewMD5 ¶ added in v1.7.3
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) FromFileChunk ¶ added in v1.7.3
func (*MD5) FromReaderChunk ¶ added in v1.7.3
func (*MD5) FromString ¶ added in v1.7.3
type MD5Pip ¶ added in v1.7.3
type MD5Pip struct {
// contains filtered or unexported fields
}
func NewMD5Pip ¶ added in v1.7.3
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) WriteBytes ¶ added in v1.7.3
func (*MD5Pip) WriteString ¶ added in v1.7.3
type MD5Result ¶ added in v1.7.3
type MD5Result struct {
// contains filtered or unexported fields
}
func NewMD5Result ¶ added in v1.7.3
func (*MD5Result) Array ¶ added in v1.7.3
func (m *MD5Result) Array() [MD5ResultLength]byte
type RemoveDuplicates ¶ added in v1.10.3
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.3
func NewRemoveDuplicates() *RemoveDuplicates
func (*RemoveDuplicates) Byte ¶ added in v1.10.3
func (d *RemoveDuplicates) Byte(s []byte) []byte
func (*RemoveDuplicates) Float32 ¶ added in v1.10.3
func (d *RemoveDuplicates) Float32(s []float32) []float32
func (*RemoveDuplicates) Float64 ¶ added in v1.10.3
func (d *RemoveDuplicates) Float64(s []float64) []float64
func (*RemoveDuplicates) Int ¶ added in v1.10.3
func (d *RemoveDuplicates) Int(s []int) []int
func (*RemoveDuplicates) Int16 ¶ added in v1.10.3
func (d *RemoveDuplicates) Int16(s []int16) []int16
func (*RemoveDuplicates) Int32 ¶ added in v1.10.3
func (d *RemoveDuplicates) Int32(s []int32) []int32
func (*RemoveDuplicates) Int64 ¶ added in v1.10.3
func (d *RemoveDuplicates) Int64(s []int64) []int64
func (*RemoveDuplicates) Int8 ¶ added in v1.10.3
func (d *RemoveDuplicates) Int8(s []int8) []int8
func (*RemoveDuplicates) String ¶ added in v1.10.3
func (d *RemoveDuplicates) String(s []string) []string
func (*RemoveDuplicates) UInt ¶ added in v1.10.3
func (d *RemoveDuplicates) UInt(s []uint) []uint
func (*RemoveDuplicates) UInt16 ¶ added in v1.10.3
func (d *RemoveDuplicates) UInt16(s []uint16) []uint16
func (*RemoveDuplicates) UInt32 ¶ added in v1.10.3
func (d *RemoveDuplicates) UInt32(s []uint32) []uint32
func (*RemoveDuplicates) UInt64 ¶ added in v1.10.3
func (d *RemoveDuplicates) UInt64(s []uint64) []uint64
func (*RemoveDuplicates) UInt8 ¶ added in v1.10.3
func (d *RemoveDuplicates) UInt8(s []uint8) []uint8
type SHA1 ¶ added in v1.7.3
type SHA1 struct{}
func NewSHA1 ¶ added in v1.7.3
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.3
func (s *SHA1) FromBytes(b []byte) *SHA1Result
func (*SHA1) FromFile ¶ added in v1.7.3
func (s *SHA1) FromFile(filename string) *SHA1Result
func (*SHA1) FromFileChunk ¶ added in v1.7.3
func (s *SHA1) FromFileChunk(filename string, chunksize int) *SHA1Result
func (*SHA1) FromReader ¶ added in v1.7.3
func (s *SHA1) FromReader(r io.Reader) *SHA1Result
func (*SHA1) FromReaderChunk ¶ added in v1.7.3
func (s *SHA1) FromReaderChunk(r io.Reader, chunksize int) *SHA1Result
func (*SHA1) FromString ¶ added in v1.7.3
func (s *SHA1) FromString(str string) *SHA1Result
type SHA1Pip ¶ added in v1.7.3
type SHA1Pip struct {
// contains filtered or unexported fields
}
func NewSHA1Pip ¶ added in v1.7.3
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.3
func (s *SHA1Pip) Result() *SHA1Result
func (*SHA1Pip) WriteBytes ¶ added in v1.7.3
func (*SHA1Pip) WriteString ¶ added in v1.7.3
type SHA1Result ¶ added in v1.7.3
type SHA1Result struct {
// contains filtered or unexported fields
}
func NewSHA1Result ¶ added in v1.7.3
func NewSHA1Result(result []byte, err error) *SHA1Result
func (*SHA1Result) Array ¶ added in v1.7.3
func (s *SHA1Result) Array() [SHA1ResultLength]byte
func (*SHA1Result) Error ¶ added in v1.7.3
func (s *SHA1Result) Error() error
func (*SHA1Result) Lower ¶ added in v1.7.3
func (s *SHA1Result) Lower() string
func (*SHA1Result) Slice ¶ added in v1.7.3
func (s *SHA1Result) Slice() []byte
func (*SHA1Result) Upper ¶ added in v1.7.3
func (s *SHA1Result) Upper() string
type SHA256 ¶ added in v1.7.3
type SHA256 struct{}
func NewSHA256 ¶ added in v1.7.3
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.3
func (s *SHA256) FromBytes(b []byte) *SHA256Result
func (*SHA256) FromFile ¶ added in v1.7.3
func (s *SHA256) FromFile(filename string) *SHA256Result
func (*SHA256) FromFileChunk ¶ added in v1.7.3
func (s *SHA256) FromFileChunk(filename string, chunksize int) *SHA256Result
func (*SHA256) FromReader ¶ added in v1.7.3
func (s *SHA256) FromReader(r io.Reader) *SHA256Result
func (*SHA256) FromReaderChunk ¶ added in v1.7.3
func (s *SHA256) FromReaderChunk(r io.Reader, chunksize int) *SHA256Result
func (*SHA256) FromString ¶ added in v1.7.3
func (s *SHA256) FromString(str string) *SHA256Result
type SHA256Pip ¶ added in v1.7.3
type SHA256Pip struct {
// contains filtered or unexported fields
}
func NewSHA256Pip ¶ added in v1.7.3
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.3
func (s *SHA256Pip) Result() *SHA256Result
func (*SHA256Pip) WriteBytes ¶ added in v1.7.3
func (*SHA256Pip) WriteString ¶ added in v1.7.3
type SHA256Result ¶ added in v1.7.3
type SHA256Result struct {
// contains filtered or unexported fields
}
func NewSHA256Result ¶ added in v1.7.3
func NewSHA256Result(result []byte, err error) *SHA256Result
func (*SHA256Result) Array ¶ added in v1.7.3
func (s *SHA256Result) Array() [SHA256ResultLength]byte
func (*SHA256Result) Error ¶ added in v1.7.3
func (s *SHA256Result) Error() error
func (*SHA256Result) Lower ¶ added in v1.7.3
func (s *SHA256Result) Lower() string
func (*SHA256Result) Slice ¶ added in v1.7.3
func (s *SHA256Result) Slice() []byte
func (*SHA256Result) Upper ¶ added in v1.7.3
func (s *SHA256Result) Upper() string
type SHA512 ¶ added in v1.7.3
type SHA512 struct{}
func NewSHA512 ¶ added in v1.7.3
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.3
func (s *SHA512) FromBytes(b []byte) *SHA512Result
func (*SHA512) FromFile ¶ added in v1.7.3
func (s *SHA512) FromFile(filename string) *SHA512Result
func (*SHA512) FromFileChunk ¶ added in v1.7.3
func (s *SHA512) FromFileChunk(filename string, chunksize int) *SHA512Result
func (*SHA512) FromReader ¶ added in v1.7.3
func (s *SHA512) FromReader(r io.Reader) *SHA512Result
func (*SHA512) FromReaderChunk ¶ added in v1.7.3
func (s *SHA512) FromReaderChunk(r io.Reader, chunksize int) *SHA512Result
func (*SHA512) FromString ¶ added in v1.7.3
func (s *SHA512) FromString(str string) *SHA512Result
type SHA512Pip ¶ added in v1.7.3
type SHA512Pip struct {
// contains filtered or unexported fields
}
func NewSHA512Pip ¶ added in v1.7.3
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.3
func (s *SHA512Pip) Result() *SHA512Result
func (*SHA512Pip) WriteBytes ¶ added in v1.7.3
func (*SHA512Pip) WriteString ¶ added in v1.7.3
type SHA512Result ¶ added in v1.7.3
type SHA512Result struct {
// contains filtered or unexported fields
}
func NewSHA512Result ¶ added in v1.7.3
func NewSHA512Result(result []byte, err error) *SHA512Result
func (*SHA512Result) Array ¶ added in v1.7.3
func (s *SHA512Result) Array() [SHA512ResultLength]byte
func (*SHA512Result) Error ¶ added in v1.7.3
func (s *SHA512Result) Error() error
func (*SHA512Result) Lower ¶ added in v1.7.3
func (s *SHA512Result) Lower() string
func (*SHA512Result) Slice ¶ added in v1.7.3
func (s *SHA512Result) Slice() []byte
func (*SHA512Result) Upper ¶ added in v1.7.3
func (s *SHA512Result) Upper() string
type Size ¶ added in v1.10.3
type Size uint64
const SizeB Size = 1
const SizeByte Size = 1
func (Size) FormatSlice ¶ added in v1.10.3
func (s Size) FormatSlice(binaryPrefixes bool) []*SizeFormatModel
FormatSlice format size
each unit is stored in a separate SizeFormatModel
func (Size) HighestUnit ¶ added in v1.10.3
func (s Size) HighestUnit(binaryPrefixes bool) *SizeFormatModel
HighestUnit return the highest unit value
type SizeFormatModel ¶ added in v1.10.3
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.10.3
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.10.3
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.10.3
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.10.3
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.10.3
func (f *SizeFormatModel) SingleSymbol() *SizeFormatModel
SingleSymbol convert symbol to single character
func (*SizeFormatModel) Size ¶ added in v1.10.3
func (f *SizeFormatModel) Size() Size
Size calculate original Size
func (*SizeFormatModel) SizeFloat ¶ added in v1.10.3
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.10.3
func (f *SizeFormatModel) String() string
func (*SizeFormatModel) StringFloat ¶ added in v1.10.3
func (f *SizeFormatModel) StringFloat() string
Click to show internal directories.
Click to hide internal directories.