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
- func HttpPost(u string, args any, contentType string, header map[string]string) []byte
- func HttpPostGet(u string, argsGET, argsPOST any, contentType string, header map[string]string) []byte
- 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 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Example ¶
p, err := DirSize("./testfile") if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func GetAvailablePort ¶
Example ¶
p, err := GetAvailablePort() if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func GetLocalIp ¶
Example ¶
p, err := GetLocalIp() if err != nil { fmt.Println(err) } fmt.Println(p)
Output:
func HourBetweenTwoTime ¶
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 ¶
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 ¶
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 ¶
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 LastPage ¶
func LastPage(w http.ResponseWriter, r *http.Request)
func MinuteBetweenTwoTime ¶
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 ¶
Example ¶
err := MkdirP("testfile/testfile") if err != nil { fmt.Println(err) }
Output:
func MonthBetweenTwoDate ¶
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 ¶
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 RandomString ¶
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 ¶
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 ¶
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 ¶
func Reload(w http.ResponseWriter, r *http.Request)
func SecondBetweenTwoTime ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Example ¶
t := TimeBase36ToUnix("s7ijax") fmt.Println(t) t = TimeBase36ToUnix("00s7ijax") fmt.Println(t)
Output: 1705675065 1705675065
func TimeNowFormat ¶
func TimeNowFormat() string
Example ¶
t := TimeNowFormat() if len(t) != 19 { fmt.Println(t) }
Output:
func TimeNowToBase36 ¶
Example ¶
s := TimeNowToBase36() if len(s) < 1 { fmt.Println(s) } s = TimeNowToBase36(8) if len(s) != 8 { fmt.Println(s) }
Output:
func TimeUnixToBase36 ¶
Example ¶
s := TimeUnixToBase36(1705675065) fmt.Println(s) s = TimeUnixToBase36(1705675065, 8) fmt.Println(s)
Output: s7ijax 00s7ijax
func TimeUnixToFormat ¶
Example ¶
t := TimeUnixToFormat(1705675065) fmt.Println(t)
Output: 2024-01-19 22:37:45
func UInt16ToBytesArray ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 WriteHTTPRespAPIFailed ¶
func WriteHTTPRespAPIFailed(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIInvalidInput ¶
func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIInvalidKey ¶
func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIOk ¶
func WriteHTTPRespAPIOk(w http.ResponseWriter, data any, msg ...any)
func WriteHTTPRespAPIProcessingFailed ¶
func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, data any, msg ...any)
func YearBetweenTwoDate ¶
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 ¶
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 ¶
type AES struct{}
type AESResult ¶
type AESResult struct {
// contains filtered or unexported fields
}
func (*AESResult) Base64 ¶
func (a *AESResult) Base64() *Base64Result
type Base64 ¶
type Base64 struct{}
func NewBase64 ¶
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 ¶
func (b *Base64) DecodeBytes(data []byte) *Base64Result
func (*Base64) DecodeString ¶
func (b *Base64) DecodeString(str string) *Base64Result
func (*Base64) EncodeBytes ¶
func (b *Base64) EncodeBytes(data []byte) *Base64Result
func (*Base64) EncodeString ¶
func (b *Base64) EncodeString(str string) *Base64Result
type Base64Result ¶
type Base64Result struct {
// contains filtered or unexported fields
}
func NewBase64Result ¶
func NewBase64Result(result string, err error) *Base64Result
func (*Base64Result) Bytes ¶
func (b *Base64Result) Bytes() []byte
func (*Base64Result) Error ¶
func (b *Base64Result) Error() error
func (*Base64Result) String ¶
func (b *Base64Result) String() string
type CRC32 ¶
type CRC32 struct{}
func NewCRC32 ¶
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 ¶
func (c *CRC32) FromBytes(data []byte) *CRC32Result
func (*CRC32) FromFile ¶
func (c *CRC32) FromFile(filename string) *CRC32Result
func (*CRC32) FromFileChunk ¶
func (c *CRC32) FromFileChunk(filename string, chunksize int) *CRC32Result
func (*CRC32) FromReader ¶
func (c *CRC32) FromReader(r io.Reader) *CRC32Result
func (*CRC32) FromReaderChunk ¶
func (c *CRC32) FromReaderChunk(r io.Reader, chunksize int) *CRC32Result
func (*CRC32) FromString ¶
func (c *CRC32) FromString(data string) *CRC32Result
type CRC32Pip ¶
type CRC32Pip struct {
// contains filtered or unexported fields
}
func NewCRC32Pip ¶
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 ¶
func (c *CRC32Pip) Result() *CRC32Result
type CRC32Result ¶
type CRC32Result struct {
// contains filtered or unexported fields
}
func NewCRC32Result ¶
func NewCRC32Result(result uint32, err error) *CRC32Result
func (*CRC32Result) Array ¶
func (c *CRC32Result) Array() [4]byte
func (*CRC32Result) Error ¶
func (c *CRC32Result) Error() error
func (*CRC32Result) Lower ¶
func (c *CRC32Result) Lower() string
func (*CRC32Result) Slice ¶
func (c *CRC32Result) Slice() []byte
func (*CRC32Result) Upper ¶
func (c *CRC32Result) Upper() string
func (*CRC32Result) Value ¶
func (c *CRC32Result) Value() uint32
type DirListModel ¶
type DirListModel struct { Files []DirListUnitModel Dirs []DirListUnitModel Error error }
func DirList ¶
func DirList(p string) *DirListModel
type DirListUnitModel ¶
type FileStatModel ¶
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 ¶
func (f *FileStatModel) IsDenied() bool
func (*FileStatModel) IsDir ¶
func (f *FileStatModel) IsDir() bool
func (*FileStatModel) IsError ¶
func (f *FileStatModel) IsError() bool
func (*FileStatModel) IsExist ¶
func (f *FileStatModel) IsExist() bool
func (*FileStatModel) IsFile ¶
func (f *FileStatModel) IsFile() bool
func (*FileStatModel) NotDenied ¶
func (f *FileStatModel) NotDenied() bool
func (*FileStatModel) NotDir ¶
func (f *FileStatModel) NotDir() bool
func (*FileStatModel) NotError ¶
func (f *FileStatModel) NotError() bool
func (*FileStatModel) NotExist ¶
func (f *FileStatModel) NotExist() bool
func (*FileStatModel) NotFile ¶
func (f *FileStatModel) NotFile() bool
type HTTPRespAPIModel ¶
type HTTPRespAPIModel struct { Code HTTPRespCode `json:"code"` Msg string `json:"msg"` Data any `json:"data,omitempty"` }
func NewHTTPResp ¶
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 ¶
func ParseHTTPResp(respstr string) *HTTPRespAPIModel
Example ¶
fmt.Println(ParseHTTPResp(`{"code":0,"msg":"ok"}`).String())
Output: {"code":0,"msg":"ok"}
func (*HTTPRespAPIModel) Bytes ¶
func (r *HTTPRespAPIModel) Bytes() []byte
func (*HTTPRespAPIModel) String ¶
func (r *HTTPRespAPIModel) String() string
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
func NewJSON ¶
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]]
type KeyResult ¶
type KeyResult struct {
// contains filtered or unexported fields
}
type MD5 ¶
type MD5 struct{}
func NewMD5 ¶
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]
type MD5Pip ¶
type MD5Pip struct {
// contains filtered or unexported fields
}
func NewMD5Pip ¶
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]
type MD5Result ¶
type MD5Result struct {
// contains filtered or unexported fields
}
func (*MD5Result) Array ¶
func (m *MD5Result) Array() [MD5ResultLength]byte
type RemoveDuplicates ¶
type RemoveDuplicates struct{}
Example ¶
s := []string{ "aaa", "bbb", "aaa", "ccc", "aaa", } ss := NewRemoveDuplicates().String(s) fmt.Println(ss)
Output: [aaa bbb ccc]
func NewRemoveDuplicates ¶
func NewRemoveDuplicates() *RemoveDuplicates
func (*RemoveDuplicates) Byte ¶
func (d *RemoveDuplicates) Byte(s []byte) []byte
func (*RemoveDuplicates) Float32 ¶
func (d *RemoveDuplicates) Float32(s []float32) []float32
func (*RemoveDuplicates) Float64 ¶
func (d *RemoveDuplicates) Float64(s []float64) []float64
func (*RemoveDuplicates) Int ¶
func (d *RemoveDuplicates) Int(s []int) []int
func (*RemoveDuplicates) Int16 ¶
func (d *RemoveDuplicates) Int16(s []int16) []int16
func (*RemoveDuplicates) Int32 ¶
func (d *RemoveDuplicates) Int32(s []int32) []int32
func (*RemoveDuplicates) Int64 ¶
func (d *RemoveDuplicates) Int64(s []int64) []int64
func (*RemoveDuplicates) Int8 ¶
func (d *RemoveDuplicates) Int8(s []int8) []int8
func (*RemoveDuplicates) String ¶
func (d *RemoveDuplicates) String(s []string) []string
func (*RemoveDuplicates) UInt ¶
func (d *RemoveDuplicates) UInt(s []uint) []uint
func (*RemoveDuplicates) UInt16 ¶
func (d *RemoveDuplicates) UInt16(s []uint16) []uint16
func (*RemoveDuplicates) UInt32 ¶
func (d *RemoveDuplicates) UInt32(s []uint32) []uint32
func (*RemoveDuplicates) UInt64 ¶
func (d *RemoveDuplicates) UInt64(s []uint64) []uint64
func (*RemoveDuplicates) UInt8 ¶
func (d *RemoveDuplicates) UInt8(s []uint8) []uint8
type SHA1 ¶
type SHA1 struct{}
func NewSHA1 ¶
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 ¶
func (s *SHA1) FromBytes(b []byte) *SHA1Result
func (*SHA1) FromFile ¶
func (s *SHA1) FromFile(filename string) *SHA1Result
func (*SHA1) FromFileChunk ¶
func (s *SHA1) FromFileChunk(filename string, chunksize int) *SHA1Result
func (*SHA1) FromReader ¶
func (s *SHA1) FromReader(r io.Reader) *SHA1Result
func (*SHA1) FromReaderChunk ¶
func (s *SHA1) FromReaderChunk(r io.Reader, chunksize int) *SHA1Result
func (*SHA1) FromString ¶
func (s *SHA1) FromString(str string) *SHA1Result
type SHA1Pip ¶
type SHA1Pip struct {
// contains filtered or unexported fields
}
func NewSHA1Pip ¶
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 ¶
func (s *SHA1Pip) Result() *SHA1Result
type SHA1Result ¶
type SHA1Result struct {
// contains filtered or unexported fields
}
func NewSHA1Result ¶
func NewSHA1Result(result []byte, err error) *SHA1Result
func (*SHA1Result) Array ¶
func (s *SHA1Result) Array() [SHA1ResultLength]byte
func (*SHA1Result) Error ¶
func (s *SHA1Result) Error() error
func (*SHA1Result) Lower ¶
func (s *SHA1Result) Lower() string
func (*SHA1Result) Slice ¶
func (s *SHA1Result) Slice() []byte
func (*SHA1Result) Upper ¶
func (s *SHA1Result) Upper() string
type SHA256 ¶
type SHA256 struct{}
func NewSHA256 ¶
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 ¶
func (s *SHA256) FromBytes(b []byte) *SHA256Result
func (*SHA256) FromFile ¶
func (s *SHA256) FromFile(filename string) *SHA256Result
func (*SHA256) FromFileChunk ¶
func (s *SHA256) FromFileChunk(filename string, chunksize int) *SHA256Result
func (*SHA256) FromReader ¶
func (s *SHA256) FromReader(r io.Reader) *SHA256Result
func (*SHA256) FromReaderChunk ¶
func (s *SHA256) FromReaderChunk(r io.Reader, chunksize int) *SHA256Result
func (*SHA256) FromString ¶
func (s *SHA256) FromString(str string) *SHA256Result
type SHA256Pip ¶
type SHA256Pip struct {
// contains filtered or unexported fields
}
func NewSHA256Pip ¶
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 ¶
func (s *SHA256Pip) Result() *SHA256Result
type SHA256Result ¶
type SHA256Result struct {
// contains filtered or unexported fields
}
func NewSHA256Result ¶
func NewSHA256Result(result []byte, err error) *SHA256Result
func (*SHA256Result) Array ¶
func (s *SHA256Result) Array() [SHA256ResultLength]byte
func (*SHA256Result) Error ¶
func (s *SHA256Result) Error() error
func (*SHA256Result) Lower ¶
func (s *SHA256Result) Lower() string
func (*SHA256Result) Slice ¶
func (s *SHA256Result) Slice() []byte
func (*SHA256Result) Upper ¶
func (s *SHA256Result) Upper() string
type SHA512 ¶
type SHA512 struct{}
func NewSHA512 ¶
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 ¶
func (s *SHA512) FromBytes(b []byte) *SHA512Result
func (*SHA512) FromFile ¶
func (s *SHA512) FromFile(filename string) *SHA512Result
func (*SHA512) FromFileChunk ¶
func (s *SHA512) FromFileChunk(filename string, chunksize int) *SHA512Result
func (*SHA512) FromReader ¶
func (s *SHA512) FromReader(r io.Reader) *SHA512Result
func (*SHA512) FromReaderChunk ¶
func (s *SHA512) FromReaderChunk(r io.Reader, chunksize int) *SHA512Result
func (*SHA512) FromString ¶
func (s *SHA512) FromString(str string) *SHA512Result
type SHA512Pip ¶
type SHA512Pip struct {
// contains filtered or unexported fields
}
func NewSHA512Pip ¶
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 ¶
func (s *SHA512Pip) Result() *SHA512Result
type SHA512Result ¶
type SHA512Result struct {
// contains filtered or unexported fields
}
func NewSHA512Result ¶
func NewSHA512Result(result []byte, err error) *SHA512Result
func (*SHA512Result) Array ¶
func (s *SHA512Result) Array() [SHA512ResultLength]byte
func (*SHA512Result) Error ¶
func (s *SHA512Result) Error() error
func (*SHA512Result) Lower ¶
func (s *SHA512Result) Lower() string
func (*SHA512Result) Slice ¶
func (s *SHA512Result) Slice() []byte
func (*SHA512Result) Upper ¶
func (s *SHA512Result) Upper() string
type Size ¶
type Size uint64
const SizeB Size = 1
const SizeByte Size = 1
func (Size) FormatSlice ¶
func (s Size) FormatSlice(binaryPrefixes bool) []*SizeFormatModel
FormatSlice format size
each unit is stored in a separate SizeFormatModel
func (Size) HighestUnit ¶
func (s Size) HighestUnit(binaryPrefixes bool) *SizeFormatModel
HighestUnit return the highest unit value
type SizeFormatModel ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (f *SizeFormatModel) SingleSymbol() *SizeFormatModel
SingleSymbol convert symbol to single character
func (*SizeFormatModel) SizeFloat ¶
func (f *SizeFormatModel) SizeFloat() Size
SizeFloat calculate original Size
due to precision, it is not guaranteed to restore the original Size
func (*SizeFormatModel) String ¶
func (f *SizeFormatModel) String() string
func (*SizeFormatModel) StringFloat ¶
func (f *SizeFormatModel) StringFloat() string
Click to show internal directories.
Click to hide internal directories.