Documentation ¶
Index ¶
- Constants
- Variables
- func BitSet(b interface{}, 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 FileStat(filename string) int
- func GetClientIP(r *http.Request) string
- func GetClientPublicIP(r *http.Request) string
- func HourBetweenTwoTime(t1, t2 time.Time) int64
- func HttpGet(u string, args any) []byte
- func HttpPost(contentType string, u string, args any) []byte
- func HttpPostGet(contentType string, u string, argsGET, argsPOST any) []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 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 interface{}) []byte
- func Uint32ToIP(i uint32) net.IP
- func Uint32ToIPAddr(i uint32) string
- func WriteHTTPRespAPIFailed(w http.ResponseWriter, msg ...any)
- func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, msg ...any)
- func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, msg ...any)
- func WriteHTTPRespAPIOk(w http.ResponseWriter, msg ...any)
- func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, msg ...any)
- func YearBetweenTwoDate(t1, t2 time.Time) int64
- func YearBetweenTwoTime(t1, t2 time.Time) int64
- type Base64
- type Base64Result
- type CRC32
- func (c *CRC32) FromBytes(data []byte) *CRC32Result
- func (c *CRC32) FromFile(filepath string) *CRC32Result
- func (c *CRC32) FromFileChunk(filepath 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 HTTPRespAPIModel
- type HTTPRespCode
- type JSON
- type MD5
- func (m *MD5) FromBytes(b []byte) *MD5Result
- func (m *MD5) FromFile(filepath string) *MD5Result
- func (m *MD5) FromFileChunk(filepath 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 SHA1
- func (s *SHA1) FromBytes(b []byte) *SHA1Result
- func (s *SHA1) FromFile(filepath string) *SHA1Result
- func (s *SHA1) FromFileChunk(filepath 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(filepath string) *SHA256Result
- func (s *SHA256) FromFileChunk(filepath 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(filepath string) *SHA512Result
- func (s *SHA512) FromFileChunk(filepath 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
Examples ¶
- BitSet
- BytesArrayToUInt16
- BytesArrayToUInt32
- BytesArrayToUInt64
- BytesCombine
- BytesSliceToUInt16
- BytesSliceToUInt32
- BytesSliceToUInt64
- BytesToUInt
- DayBetweenTwoDate
- DayBetweenTwoTime
- FileStat
- HourBetweenTwoTime
- HttpGet
- HttpPost
- HttpPostGet
- MinuteBetweenTwoTime
- MonthBetweenTwoDate
- MonthBetweenTwoTime
- NewBase64
- NewCRC32
- NewCRC32Pip
- NewHTTPResp
- NewJSON
- NewJSONResult
- NewMD5
- NewMD5Pip
- NewSHA1
- NewSHA1Pip
- NewSHA256
- NewSHA256Pip
- NewSHA512
- NewSHA512Pip
- ParseHTTPResp
- RandomString
- RandomStringAtLeastOnce
- RandomStringWithTimestamp
- SecondBetweenTwoTime
- SplitPath
- SplitPathRepeat
- SplitPathSkip
- TcpPortIsOpen
- TcpPortIsOpenByAddr
- TimeBase36ToUnix
- TimeNowFormat
- TimeNowToBase36
- TimeUnixToBase36
- TimeUnixToFormat
- UInt16ToBytesArray
- UInt16ToBytesSlice
- UInt32ToBytesArray
- UInt32ToBytesSlice
- UInt64ToBytesArray
- UInt64ToBytesSlice
- UIntToBytes
- YearBetweenTwoDate
- YearBetweenTwoTime
Constants ¶
View Source
const ( FileStatNotExist = 0 FileStatIsDir = 1 FileStatIsFile = 2 )
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; charset=utf-8" HTTPContentTypeJson = "application/json; charset=UTF-8" )
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.1
Example ¶
bs := [2]byte{255, 255} val := BytesArrayToUInt16(bs) fmt.Println(val) bs = [2]byte{127, 255} val = BytesArrayToUInt16(bs) fmt.Println(val) bs = [2]byte{127, 254} val = BytesArrayToUInt16(bs) fmt.Println(val)
Output: 65535 32767 32766
func BytesArrayToUInt32 ¶ added in v1.7.1
Example ¶
bs := [4]byte{255, 255, 255, 255} val := BytesArrayToUInt32(bs) fmt.Println(val) bs = [4]byte{127, 255, 255, 255} val = BytesArrayToUInt32(bs) fmt.Println(val) bs = [4]byte{127, 254, 254, 254} val = BytesArrayToUInt32(bs) fmt.Println(val)
Output: 4294967295 2147483647 2147417854
func BytesArrayToUInt64 ¶ added in v1.7.1
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.1
Example ¶
bs := []byte{255, 255} val := BytesSliceToUInt16(bs) fmt.Println(val) bs = []byte{127, 255} val = BytesSliceToUInt16(bs) fmt.Println(val) bs = []byte{127, 254} val = BytesSliceToUInt16(bs) fmt.Println(val)
Output: 65535 32767 32766
func BytesSliceToUInt32 ¶ added in v1.7.1
Example ¶
bs := []byte{255, 255, 255, 255} val := BytesSliceToUInt32(bs) fmt.Println(val) bs = []byte{127, 255, 255, 255} val = BytesSliceToUInt32(bs) fmt.Println(val) bs = []byte{127, 254, 254, 254} val = BytesSliceToUInt32(bs) fmt.Println(val)
Output: 4294967295 2147483647 2147417854
func BytesSliceToUInt64 ¶ added in v1.7.1
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.1
Example ¶
t1 := int64(1705628326) t2 := int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(DayBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0))) fmt.Println(DayBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(DayBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output: 2024-01-19 09:38:46 -> 2024-01-18 22:37:45 0 1 -1
func DayBetweenTwoTime ¶ added in v1.7.1
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 FileStat ¶
Example ¶
if FileStat("testfile") == FileStatIsDir { fmt.Println("FileStatIsDir") } if FileStat("testfile/testFile1") == FileStatIsFile { fmt.Println("FileStatIsFile") } if FileStat("testfile/testFile2") == FileStatNotExist { fmt.Println("FileStatNotExist") }
Output: FileStatIsDir FileStatIsFile FileStatNotExist
func GetClientIP ¶ added in v1.7.1
func GetClientPublicIP ¶ added in v1.7.1
func HourBetweenTwoTime ¶ added in v1.7.1
Example ¶
t1 := int64(1705628326) t2 := int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(HourBetweenTwoTime(time.Unix(t1, 0), time.Unix(t1, 0))) fmt.Println(HourBetweenTwoTime(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(HourBetweenTwoTime(time.Unix(t2, 0), time.Unix(t1, 0)))
Output: 2024-01-19 09:38:46 -> 2024-01-18 22:37:45 0 11 -11
func HttpGet ¶ added in v1.7.1
Example ¶
i := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts/1", nil)) i1 := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts", map[string]any{"id": 1})) i2 := NewJSONResult(HttpGet("https://jsonplaceholder.typicode.com/posts", map[string]any{"id": 2})) if fmt.Sprint(i.Map()["id"]) != "1" { fmt.Println(i) } if fmt.Sprint(i1.Map()["id"]) != "1" { fmt.Println(i1) } if fmt.Sprint(i2.MapArray()[0]["id"]) != "2" { fmt.Println(i2) }
Output:
func HttpPost ¶ added in v1.7.1
Example ¶
i1 := NewJSONResult(HttpPost(HTTPContentTypeUrlencoded, "https://jsonplaceholder.typicode.com/posts", map[string]any{"title": "t1", "body": "b1", "userId": 1})) if fmt.Sprint(i1.Map()["id"]) != "101" { fmt.Println(i1) }
Output:
func HttpPostGet ¶ added in v1.7.1
Example ¶
i1 := NewJSONResult(HttpPostGet(HTTPContentTypeUrlencoded, "https://jsonplaceholder.typicode.com/posts", map[string]any{"title": "t2", "body": "b2", "userId": 2}, map[string]any{"title": "t1", "body": "b1", "userId": 1})) if fmt.Sprint(i1.Map()["id"]) != "101" { fmt.Println(i1) }
Output:
func IPAddrToUint32 ¶ added in v1.7.1
func IsLocalIPAddr ¶ added in v1.7.1
func MinuteBetweenTwoTime ¶ added in v1.7.1
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 MonthBetweenTwoDate ¶ added in v1.7.1
Example ¶
t1 := int64(1739929126) t2 := int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0))) fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0))) t1 = int64(1737211064) t2 = int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0))) t1 = int64(1737211066) t2 = int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(MonthBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(MonthBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output: 2025-02-19 09:38:46 -> 2024-01-18 22:37:45 0 13 -13 2025-01-18 22:37:44 -> 2024-01-18 22:37:45 12 -12 2025-01-18 22:37:46 -> 2024-01-18 22:37:45 12 -12
func MonthBetweenTwoTime ¶ added in v1.7.1
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 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 ¶ added in v1.7.1
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 RespRedirect ¶ added in v1.7.1
func RespRedirect(w http.ResponseWriter, r *http.Request, url string)
func SecondBetweenTwoTime ¶ added in v1.7.1
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 ¶ added in v1.7.1
Example ¶
ip := "172.16.0.1" fmt.Println(TcpPortIsOpen(ip, "22")) fmt.Println(TcpPortIsOpen(ip, "80")) fmt.Println(TcpPortIsOpen(ip, "443")) fmt.Println(TcpPortIsOpen(ip, "444"))
Output: true true true false
func TcpPortIsOpenByAddr ¶ added in v1.7.1
Example ¶
fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:22")) fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:80")) fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:443")) fmt.Println(TcpPortIsOpenByAddr("172.16.0.1:444"))
Output: true true true false
func TimeBase36ToUnix ¶ added in v1.7.1
Example ¶
t := TimeBase36ToUnix("s7ijax") fmt.Println(t) t = TimeBase36ToUnix("00s7ijax") fmt.Println(t)
Output: 1705675065 1705675065
func TimeNowFormat ¶ added in v1.7.1
func TimeNowFormat() string
Example ¶
t := TimeNowFormat() if len(t) != 19 { fmt.Println(t) }
Output:
func TimeNowToBase36 ¶ added in v1.7.1
Example ¶
s := TimeNowToBase36() if len(s) < 1 { fmt.Println(s) } s = TimeNowToBase36(8) if len(s) != 8 { fmt.Println(s) }
Output:
func TimeUnixToBase36 ¶ added in v1.7.1
Example ¶
s := TimeUnixToBase36(1705675065) fmt.Println(s) s = TimeUnixToBase36(1705675065, 8) fmt.Println(s)
Output: s7ijax 00s7ijax
func TimeUnixToFormat ¶ added in v1.7.1
Example ¶
t := TimeUnixToFormat(1705675065) fmt.Println(t)
Output: 2024-01-19 22:37:45
func UInt16ToBytesArray ¶ added in v1.7.1
Example ¶
val := uint16(65535) bs := UInt16ToBytesArray(val) fmt.Println(bs) val /= 2 bs = UInt16ToBytesArray(val) fmt.Println(bs) val -= 1 bs = UInt16ToBytesArray(val) fmt.Println(bs)
Output: [255 255] [127 255] [127 254]
func UInt16ToBytesSlice ¶ added in v1.7.1
Example ¶
val := uint16(65535) bs := UInt16ToBytesSlice(val) fmt.Println(bs) val /= 2 bs = UInt16ToBytesSlice(val) fmt.Println(bs) val -= 1 bs = UInt16ToBytesSlice(val) fmt.Println(bs)
Output: [255 255] [127 255] [127 254]
func UInt32ToBytesArray ¶ added in v1.7.1
Example ¶
val := uint32(4294967295) bs := UInt32ToBytesArray(val) fmt.Println(bs) val = uint32(2147483647) bs = UInt32ToBytesArray(val) fmt.Println(bs) val = uint32(2147417854) bs = UInt32ToBytesArray(val) fmt.Println(bs)
Output: [255 255 255 255] [127 255 255 255] [127 254 254 254]
func UInt32ToBytesSlice ¶ added in v1.7.1
Example ¶
val := uint32(4294967295) bs := UInt32ToBytesSlice(val) fmt.Println(bs) val = uint32(2147483647) bs = UInt32ToBytesSlice(val) fmt.Println(bs) val = uint32(2147417854) bs = UInt32ToBytesSlice(val) fmt.Println(bs)
Output: [255 255 255 255] [127 255 255 255] [127 254 254 254]
func UInt64ToBytesArray ¶ added in v1.7.1
Example ¶
val := uint64(18446744073709551615) bs := UInt64ToBytesArray(val) fmt.Println(bs) val = uint64(9223372036854775807) bs = UInt64ToBytesArray(val) fmt.Println(bs) val = uint64(9223089458054627070) bs = UInt64ToBytesArray(val) fmt.Println(bs)
Output: [255 255 255 255 255 255 255 255] [127 255 255 255 255 255 255 255] [127 254 254 254 254 254 254 254]
func UInt64ToBytesSlice ¶ added in v1.7.1
Example ¶
val := uint64(18446744073709551615) bs := UInt64ToBytesSlice(val) fmt.Println(bs) val = uint64(9223372036854775807) bs = UInt64ToBytesSlice(val) fmt.Println(bs) val = uint64(9223089458054627070) bs = UInt64ToBytesSlice(val) fmt.Println(bs)
Output: [255 255 255 255 255 255 255 255] [127 255 255 255 255 255 255 255] [127 254 254 254 254 254 254 254]
func UIntToBytes ¶
func UIntToBytes(i interface{}) []byte
Example ¶
val8 := uint8(254) bs := UIntToBytes(val8) fmt.Println(bs) val16 := uint16(65534) bs = UIntToBytes(val16) fmt.Println(bs) val32 := uint32(4294967294) bs = UIntToBytes(val32) fmt.Println(bs) val64 := uint64(18446744073709551614) bs = UIntToBytes(val64) fmt.Println(bs) valErr := "" bs = UIntToBytes(valErr) fmt.Println(bs)
Output: [254] [255 254] [255 255 255 254] [255 255 255 255 255 255 255 254] []
func Uint32ToIP ¶ added in v1.7.1
func Uint32ToIPAddr ¶ added in v1.7.1
func WriteHTTPRespAPIFailed ¶ added in v1.7.1
func WriteHTTPRespAPIFailed(w http.ResponseWriter, msg ...any)
func WriteHTTPRespAPIInvalidInput ¶ added in v1.7.1
func WriteHTTPRespAPIInvalidInput(w http.ResponseWriter, msg ...any)
func WriteHTTPRespAPIInvalidKey ¶ added in v1.7.1
func WriteHTTPRespAPIInvalidKey(w http.ResponseWriter, msg ...any)
func WriteHTTPRespAPIOk ¶ added in v1.7.1
func WriteHTTPRespAPIOk(w http.ResponseWriter, msg ...any)
func WriteHTTPRespAPIProcessingFailed ¶ added in v1.7.1
func WriteHTTPRespAPIProcessingFailed(w http.ResponseWriter, msg ...any)
func YearBetweenTwoDate ¶ added in v1.7.1
Example ¶
t1 := int64(1739929126) t2 := int64(1705588665) fmt.Printf("%s -> %s\n", TimeUnixToFormat(t1), TimeUnixToFormat(t2)) fmt.Println(YearBetweenTwoDate(time.Unix(t1, 0), time.Unix(t1, 0))) fmt.Println(YearBetweenTwoDate(time.Unix(t1, 0), time.Unix(t2, 0))) fmt.Println(YearBetweenTwoDate(time.Unix(t2, 0), time.Unix(t1, 0)))
Output: 2025-02-19 09:38:46 -> 2024-01-18 22:37:45 0 1 -1
func YearBetweenTwoTime ¶ added in v1.7.1
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 Base64 ¶ added in v1.7.1
type Base64 struct{}
func NewBase64 ¶ added in v1.7.1
func NewBase64() *Base64
Example ¶
testString := "Akvicor" testStringBase64 := "QWt2aWNvcg==" encodeS := NewBase64().EncodeString(testString) fmt.Println(encodeS) encodeB := NewBase64().EncodeBytes([]byte(testString)) fmt.Println(encodeB.String()) decodeS := NewBase64().DecodeString(testStringBase64) if decodeS.Error() == nil { fmt.Println(decodeS) } decodeB := NewBase64().DecodeBytes([]byte(testStringBase64)) fmt.Println(decodeB.Bytes())
Output: QWt2aWNvcg== QWt2aWNvcg== Akvicor [65 107 118 105 99 111 114]
func (*Base64) DecodeBytes ¶ added in v1.7.1
func (b *Base64) DecodeBytes(data []byte) *Base64Result
func (*Base64) DecodeString ¶ added in v1.7.1
func (b *Base64) DecodeString(str string) *Base64Result
func (*Base64) EncodeBytes ¶ added in v1.7.1
func (b *Base64) EncodeBytes(data []byte) *Base64Result
func (*Base64) EncodeString ¶ added in v1.7.1
func (b *Base64) EncodeString(str string) *Base64Result
type Base64Result ¶ added in v1.7.1
type Base64Result struct {
// contains filtered or unexported fields
}
func NewBase64Result ¶ added in v1.7.1
func NewBase64Result(result string, err error) *Base64Result
func (*Base64Result) Bytes ¶ added in v1.7.1
func (b *Base64Result) Bytes() []byte
func (*Base64Result) Error ¶ added in v1.7.1
func (b *Base64Result) Error() error
func (*Base64Result) String ¶ added in v1.7.1
func (b *Base64Result) String() string
type CRC32 ¶ added in v1.7.1
type CRC32 struct{}
func NewCRC32 ¶ added in v1.7.1
func NewCRC32() *CRC32
Example ¶
crc := NewCRC32() res := crc.FromString("Akvicor") if res.Error() == nil { fmt.Println(res.Value()) fmt.Println(res.Lower()) fmt.Println(res.Upper()) }
Output: 996205005 3b60e1cd 3B60E1CD
func (*CRC32) FromBytes ¶ added in v1.7.1
func (c *CRC32) FromBytes(data []byte) *CRC32Result
func (*CRC32) FromFile ¶ added in v1.7.1
func (c *CRC32) FromFile(filepath string) *CRC32Result
func (*CRC32) FromFileChunk ¶ added in v1.7.1
func (c *CRC32) FromFileChunk(filepath string, chunksize int) *CRC32Result
func (*CRC32) FromReader ¶ added in v1.7.1
func (c *CRC32) FromReader(r io.Reader) *CRC32Result
func (*CRC32) FromReaderChunk ¶ added in v1.7.1
func (c *CRC32) FromReaderChunk(r io.Reader, chunksize int) *CRC32Result
func (*CRC32) FromString ¶ added in v1.7.1
func (c *CRC32) FromString(data string) *CRC32Result
type CRC32Pip ¶ added in v1.7.1
type CRC32Pip struct {
// contains filtered or unexported fields
}
func NewCRC32Pip ¶ added in v1.7.1
func NewCRC32Pip() *CRC32Pip
Example ¶
cp := NewCRC32Pip() io.WriteString(cp, "Akvicor") res := cp.Result() if res.Error() == nil { fmt.Println(res.Array()) fmt.Println(res.Slice()) }
Output: [59 96 225 205] [59 96 225 205]
func (*CRC32Pip) Result ¶ added in v1.7.1
func (c *CRC32Pip) Result() *CRC32Result
func (*CRC32Pip) WriteBytes ¶ added in v1.7.1
func (*CRC32Pip) WriteString ¶ added in v1.7.1
type CRC32Result ¶ added in v1.7.1
type CRC32Result struct {
// contains filtered or unexported fields
}
func NewCRC32Result ¶ added in v1.7.1
func NewCRC32Result(result uint32, err error) *CRC32Result
func (*CRC32Result) Array ¶ added in v1.7.1
func (c *CRC32Result) Array() [4]byte
func (*CRC32Result) Error ¶ added in v1.7.1
func (c *CRC32Result) Error() error
func (*CRC32Result) Lower ¶ added in v1.7.1
func (c *CRC32Result) Lower() string
func (*CRC32Result) Slice ¶ added in v1.7.1
func (c *CRC32Result) Slice() []byte
func (*CRC32Result) Upper ¶ added in v1.7.1
func (c *CRC32Result) Upper() string
func (*CRC32Result) Value ¶ added in v1.7.1
func (c *CRC32Result) Value() uint32
type HTTPRespAPIModel ¶ added in v1.7.1
type HTTPRespAPIModel struct { Code HTTPRespCode `json:"code"` Msg string `json:"msg"` }
func NewHTTPResp ¶ added in v1.7.1
func NewHTTPResp(code HTTPRespCode, msg string) *HTTPRespAPIModel
NewHTTPResp Util Reserved code range (-100,100)
Example ¶
fmt.Println(NewHTTPResp(HTTPRespCodeOKCode, HTTPRespCodeOKMsg))
Output: {"code":0,"msg":"ok"}
func ParseHTTPResp ¶ added in v1.7.1
func ParseHTTPResp(respstr string) *HTTPRespAPIModel
Example ¶
fmt.Println(ParseHTTPResp(`{"code":0,"msg":"ok"}`).String())
Output: {"code":0,"msg":"ok"}
func (*HTTPRespAPIModel) String ¶ added in v1.7.1
func (r *HTTPRespAPIModel) String() string
type HTTPRespCode ¶ added in v1.7.1
type HTTPRespCode int
HTTPRespCode Util Reserved code range (-100,100)
type JSON ¶ added in v1.7.1
type JSON struct {
// contains filtered or unexported fields
}
func NewJSON ¶ added in v1.7.1
Example ¶
type TestStruct struct { Name string `json:"name"` Age int `json:"age"` } test1 := TestStruct{ Name: "Akvicor", Age: 17, } res := NewJSON(&test1, false) if res.Error() == nil { fmt.Println(res.String()) fmt.Println(res.Bytes()) fmt.Println(res.Map()) fmt.Println(res.Map(0)) fmt.Println(res.Map(10)) fmt.Println(res.MapArray()) fmt.Println(NewJSON(res.Map(), false)) } test2 := [...]TestStruct{{Name: "Akvicor", Age: 17}, {Name: "MIU", Age: 17}} res = NewJSON(&test2, true) if res.Error() == nil { fmt.Println(res.Map(1)) fmt.Println(res.MapArray()) }
Output: {"name":"Akvicor","age":17} [123 34 110 97 109 101 34 58 34 65 107 118 105 99 111 114 34 44 34 97 103 101 34 58 49 55 125] map[age:17 name:Akvicor] map[age:17 name:Akvicor] map[age:17 name:Akvicor] [map[age:17 name:Akvicor]] {"age":17,"name":"Akvicor"} map[age:17 name:MIU] [map[age:17 name:Akvicor] map[age:17 name:MIU]]
func NewJSONResult ¶ added in v1.7.1
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 MD5 ¶ added in v1.7.1
type MD5 struct{}
func NewMD5 ¶ added in v1.7.1
func NewMD5() *MD5
Example ¶
m5 := NewMD5() res := m5.FromString("Akvicor") if res.Error() == nil { fmt.Println(res.Lower()) fmt.Println(res.Upper()) fmt.Println(res.Slice()) }
Output: f812705c26adc52561415189e5f78edb F812705C26ADC52561415189E5F78EDB [248 18 112 92 38 173 197 37 97 65 81 137 229 247 142 219]
func (*MD5) FromFileChunk ¶ added in v1.7.1
func (*MD5) FromReaderChunk ¶ added in v1.7.1
func (*MD5) FromString ¶ added in v1.7.1
type MD5Pip ¶ added in v1.7.1
type MD5Pip struct {
// contains filtered or unexported fields
}
func NewMD5Pip ¶ added in v1.7.1
func NewMD5Pip() *MD5Pip
Example ¶
mp := NewMD5Pip() io.WriteString(mp, "Akvicor") 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.1
func (*MD5Pip) WriteString ¶ added in v1.7.1
type MD5Result ¶ added in v1.7.1
type MD5Result struct {
// contains filtered or unexported fields
}
func NewMD5Result ¶ added in v1.7.1
func (*MD5Result) Array ¶ added in v1.7.1
func (m *MD5Result) Array() [MD5ResultLength]byte
type SHA1 ¶ added in v1.7.1
type SHA1 struct{}
func NewSHA1 ¶ added in v1.7.1
func NewSHA1() *SHA1
Example ¶
s := NewSHA1() res := s.FromString("Akvicor") if res.Error() == nil { fmt.Println(res.Lower()) fmt.Println(res.Upper()) fmt.Println(res.Slice()) }
Output: 49296886bfedac0dd0399030bc0dbe12e5eed489 49296886BFEDAC0DD0399030BC0DBE12E5EED489 [73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137]
func (*SHA1) FromBytes ¶ added in v1.7.1
func (s *SHA1) FromBytes(b []byte) *SHA1Result
func (*SHA1) FromFile ¶ added in v1.7.1
func (s *SHA1) FromFile(filepath string) *SHA1Result
func (*SHA1) FromFileChunk ¶ added in v1.7.1
func (s *SHA1) FromFileChunk(filepath string, chunksize int) *SHA1Result
func (*SHA1) FromReader ¶ added in v1.7.1
func (s *SHA1) FromReader(r io.Reader) *SHA1Result
func (*SHA1) FromReaderChunk ¶ added in v1.7.1
func (s *SHA1) FromReaderChunk(r io.Reader, chunksize int) *SHA1Result
func (*SHA1) FromString ¶ added in v1.7.1
func (s *SHA1) FromString(str string) *SHA1Result
type SHA1Pip ¶ added in v1.7.1
type SHA1Pip struct {
// contains filtered or unexported fields
}
func NewSHA1Pip ¶ added in v1.7.1
func NewSHA1Pip() *SHA1Pip
Example ¶
sp := NewSHA1Pip() io.WriteString(sp, "Akvicor") res := sp.Result() if res.Error() == nil { fmt.Println(res.Array()) fmt.Println(res.Slice()) }
Output: [73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137] [73 41 104 134 191 237 172 13 208 57 144 48 188 13 190 18 229 238 212 137]
func (*SHA1Pip) Result ¶ added in v1.7.1
func (s *SHA1Pip) Result() *SHA1Result
func (*SHA1Pip) WriteBytes ¶ added in v1.7.1
func (*SHA1Pip) WriteString ¶ added in v1.7.1
type SHA1Result ¶ added in v1.7.1
type SHA1Result struct {
// contains filtered or unexported fields
}
func NewSHA1Result ¶ added in v1.7.1
func NewSHA1Result(result []byte, err error) *SHA1Result
func (*SHA1Result) Array ¶ added in v1.7.1
func (s *SHA1Result) Array() [SHA1ResultLength]byte
func (*SHA1Result) Error ¶ added in v1.7.1
func (s *SHA1Result) Error() error
func (*SHA1Result) Lower ¶ added in v1.7.1
func (s *SHA1Result) Lower() string
func (*SHA1Result) Slice ¶ added in v1.7.1
func (s *SHA1Result) Slice() []byte
func (*SHA1Result) Upper ¶ added in v1.7.1
func (s *SHA1Result) Upper() string
type SHA256 ¶ added in v1.7.1
type SHA256 struct{}
func NewSHA256 ¶ added in v1.7.1
func NewSHA256() *SHA256
Example ¶
s := NewSHA256() res := s.FromString("Akvicor") if res.Error() == nil { fmt.Println(res.Lower()) fmt.Println(res.Upper()) fmt.Println(res.Slice()) }
Output: 36acc0924a190c77386cd819a3bff60251345e8654399f68e8b740a1afa62ff5 36ACC0924A190C77386CD819A3BFF60251345E8654399F68E8B740A1AFA62FF5 [54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245]
func (*SHA256) FromBytes ¶ added in v1.7.1
func (s *SHA256) FromBytes(b []byte) *SHA256Result
func (*SHA256) FromFile ¶ added in v1.7.1
func (s *SHA256) FromFile(filepath string) *SHA256Result
func (*SHA256) FromFileChunk ¶ added in v1.7.1
func (s *SHA256) FromFileChunk(filepath string, chunksize int) *SHA256Result
func (*SHA256) FromReader ¶ added in v1.7.1
func (s *SHA256) FromReader(r io.Reader) *SHA256Result
func (*SHA256) FromReaderChunk ¶ added in v1.7.1
func (s *SHA256) FromReaderChunk(r io.Reader, chunksize int) *SHA256Result
func (*SHA256) FromString ¶ added in v1.7.1
func (s *SHA256) FromString(str string) *SHA256Result
type SHA256Pip ¶ added in v1.7.1
type SHA256Pip struct {
// contains filtered or unexported fields
}
func NewSHA256Pip ¶ added in v1.7.1
func NewSHA256Pip() *SHA256Pip
Example ¶
sp := NewSHA256Pip() io.WriteString(sp, "Akvicor") res := sp.Result() if res.Error() == nil { fmt.Println(res.Array()) fmt.Println(res.Slice()) }
Output: [54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245] [54 172 192 146 74 25 12 119 56 108 216 25 163 191 246 2 81 52 94 134 84 57 159 104 232 183 64 161 175 166 47 245]
func (*SHA256Pip) Result ¶ added in v1.7.1
func (s *SHA256Pip) Result() *SHA256Result
func (*SHA256Pip) WriteBytes ¶ added in v1.7.1
func (*SHA256Pip) WriteString ¶ added in v1.7.1
type SHA256Result ¶ added in v1.7.1
type SHA256Result struct {
// contains filtered or unexported fields
}
func NewSHA256Result ¶ added in v1.7.1
func NewSHA256Result(result []byte, err error) *SHA256Result
func (*SHA256Result) Array ¶ added in v1.7.1
func (s *SHA256Result) Array() [SHA256ResultLength]byte
func (*SHA256Result) Error ¶ added in v1.7.1
func (s *SHA256Result) Error() error
func (*SHA256Result) Lower ¶ added in v1.7.1
func (s *SHA256Result) Lower() string
func (*SHA256Result) Slice ¶ added in v1.7.1
func (s *SHA256Result) Slice() []byte
func (*SHA256Result) Upper ¶ added in v1.7.1
func (s *SHA256Result) Upper() string
type SHA512 ¶ added in v1.7.1
type SHA512 struct{}
func NewSHA512 ¶ added in v1.7.1
func NewSHA512() *SHA512
Example ¶
s := NewSHA512() res := s.FromString("Akvicor") if res.Error() == nil { fmt.Println(res.Lower()) fmt.Println(res.Upper()) fmt.Println(res.Slice()) }
Output: 6fdfb481af6573ac49d4031d22f0d73f0f24ea8cb113982593ec65ab085b0635b46d7683aa3f4ef36c2cb25a7bb8ba8cbae2fa3e9810d35b1c70a93f37586361 6FDFB481AF6573AC49D4031D22F0D73F0F24EA8CB113982593EC65AB085B0635B46D7683AA3F4EF36C2CB25A7BB8BA8CBAE2FA3E9810D35B1C70A93F37586361 [111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97]
func (*SHA512) FromBytes ¶ added in v1.7.1
func (s *SHA512) FromBytes(b []byte) *SHA512Result
func (*SHA512) FromFile ¶ added in v1.7.1
func (s *SHA512) FromFile(filepath string) *SHA512Result
func (*SHA512) FromFileChunk ¶ added in v1.7.1
func (s *SHA512) FromFileChunk(filepath string, chunksize int) *SHA512Result
func (*SHA512) FromReader ¶ added in v1.7.1
func (s *SHA512) FromReader(r io.Reader) *SHA512Result
func (*SHA512) FromReaderChunk ¶ added in v1.7.1
func (s *SHA512) FromReaderChunk(r io.Reader, chunksize int) *SHA512Result
func (*SHA512) FromString ¶ added in v1.7.1
func (s *SHA512) FromString(str string) *SHA512Result
type SHA512Pip ¶ added in v1.7.1
type SHA512Pip struct {
// contains filtered or unexported fields
}
func NewSHA512Pip ¶ added in v1.7.1
func NewSHA512Pip() *SHA512Pip
Example ¶
sp := NewSHA512Pip() io.WriteString(sp, "Akvicor") res := sp.Result() if res.Error() == nil { fmt.Println(res.Array()) fmt.Println(res.Slice()) }
Output: [111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97] [111 223 180 129 175 101 115 172 73 212 3 29 34 240 215 63 15 36 234 140 177 19 152 37 147 236 101 171 8 91 6 53 180 109 118 131 170 63 78 243 108 44 178 90 123 184 186 140 186 226 250 62 152 16 211 91 28 112 169 63 55 88 99 97]
func (*SHA512Pip) Result ¶ added in v1.7.1
func (s *SHA512Pip) Result() *SHA512Result
func (*SHA512Pip) WriteBytes ¶ added in v1.7.1
func (*SHA512Pip) WriteString ¶ added in v1.7.1
type SHA512Result ¶ added in v1.7.1
type SHA512Result struct {
// contains filtered or unexported fields
}
func NewSHA512Result ¶ added in v1.7.1
func NewSHA512Result(result []byte, err error) *SHA512Result
func (*SHA512Result) Array ¶ added in v1.7.1
func (s *SHA512Result) Array() [SHA512ResultLength]byte
func (*SHA512Result) Error ¶ added in v1.7.1
func (s *SHA512Result) Error() error
func (*SHA512Result) Lower ¶ added in v1.7.1
func (s *SHA512Result) Lower() string
func (*SHA512Result) Slice ¶ added in v1.7.1
func (s *SHA512Result) Slice() []byte
func (*SHA512Result) Upper ¶ added in v1.7.1
func (s *SHA512Result) Upper() string
Click to show internal directories.
Click to hide internal directories.