Documentation ¶
Overview ¶
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools ¶
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2016-2023 volibear<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2016-2024 volibear<volibearw@gmail.com>. All rights reserved.
Package tools Copyright 2023 marcello<volibearw@gmail.com>. All rights reserved.
Package tools
Index ¶
- Constants
- func Base64RawStdDecoding(s string) string
- func Base64RawStdEncoding(s string) string
- func Base64RawURLDecoding(s string) string
- func Base64RawURLEncoding(s string) string
- func Base64StdDecoding(s string) string
- func Base64StdEncoding(s string) string
- func Base64UrlDecoding(s string) string
- func Base64UrlEncoding(s string) string
- func BytesToString(b []byte) string
- func Close(f io.Closer)
- func Copy(dst string, src ...string) error
- func CopyFile(dst, src string) error
- func CreateEmptyFile(filename string) error
- func DirHasPrefix(s, prefix string) bool
- func FormatTime[T constraints.Float | constraints.Integer](sec T, nsec T) string
- func GetCurrentDirectory() string
- func InSlice[T comparable](need T, arr []T) bool
- func IsNumber(s string) bool
- func JSONMarshalByte(v interface{}) []byte
- func JSONMarshalString(v interface{}) string
- func Md5(s string) string
- func Md5File(filePath string) (string, error)
- func PathExists(path string) (bool, error)
- func RandomString(length uint, charType randomType) (s string)
- func RandomStringWithComplex(length uint) string
- func RandomStringWithDigital(length uint) string
- func RandomStringWithGeneral(length uint) string
- func RandomStringWithLowercase(length uint) string
- func RandomStringWithMajuscule(length uint) string
- func ReCreateDirectory(dir string) error
- func RemoveLastSeparator(path string) string
- func RemoveSameFromStringSlice(slice []string) []string
- func ReverseByte(s []byte) []byte
- func ReverseString(s string) string
- func SliceRemove[T comparable](remove []T, s []T) []T
- func SliceTrimSame[T comparable](s []T) []T
- func StringToBytes(s string) []byte
- func SubString(s string, pos uint, to ...uint) string
- func Unzip(ctx context.Context, filename string, saveAs string, ...) error
- func UnzipGBKHandler(f **zip.File)
- func XMLMarshalByte(v interface{}) []byte
- func XMLMarshalString(v interface{}) string
- func Zip(zipPath string, paths ...string) error
- type DownloadFile
- func (d *DownloadFile) DisableCreateDirectory()
- func (d *DownloadFile) DownloadFromUrl(ctx context.Context, url string) (n int64, err error)
- func (d *DownloadFile) GetFilename() string
- func (d *DownloadFile) SaveAsDirectory(directory string)
- func (d *DownloadFile) SaveAsFilename(filename string)
- func (d *DownloadFile) Timeout(timeout time.Duration)
- type FTP
- func (w *FTP) ChangeDir(ctx context.Context, path string) (err error)
- func (w *FTP) Close() (err error)
- func (w *FTP) Connect(ctx context.Context) (err error)
- func (w *FTP) Download(ctx context.Context, path, saveAsDirectory string, saveAsFilename ...string) (err error)
- func (w *FTP) GetServerConn() *ftp.ServerConn
- type PaginationData
- type TSMap
- func (m *TSMap[K, T]) Delete(key K)
- func (m *TSMap[K, T]) Len() int64
- func (m *TSMap[K, T]) Load(key K) (T, bool)
- func (m *TSMap[K, T]) LoadAndDelete(key K) (T, bool)
- func (m *TSMap[K, T]) LoadOrStore(key K, value T) (T, bool)
- func (m *TSMap[K, T]) Range(f func(key K, value T) bool)
- func (m *TSMap[K, T]) Store(key K, value T)
- type TSSlice
- func (s *TSSlice[T]) Append(v ...T)
- func (s *TSSlice[T]) Clone() *TSSlice[T]
- func (s *TSSlice[T]) Get() []T
- func (s *TSSlice[T]) Index(index int) (T, error)
- func (s *TSSlice[T]) Insert(i int, v ...T)
- func (s *TSSlice[T]) Len() int
- func (s *TSSlice[T]) Remove(i, j int) error
- func (s *TSSlice[T]) Reverse()
Constants ¶
const ( // RandomLowercase lowercase RandomLowercase randomType = 2 << iota // RandomMajuscule majuscule RandomMajuscule // RandomDigital digital RandomDigital // RandomSymbol symbol RandomSymbol // RandomAll all RandomAll = RandomLowercase | RandomMajuscule | RandomDigital | RandomSymbol )
const IsDarwin = false
const IsLinux = true
const IsWindows = false
const TimeFormatString = "2006-01-02 15:04:05"
TimeFormatString time layout
Variables ¶
This section is empty.
Functions ¶
func Base64RawStdDecoding ¶ added in v0.0.17
Base64RawStdDecoding ...
func Base64RawStdEncoding ¶ added in v0.0.17
Base64RawStdEncoding ...
func Base64RawURLDecoding ¶ added in v0.0.17
Base64RawURLDecoding ...
func Base64RawURLEncoding ¶ added in v0.0.17
Base64RawURLEncoding ...
func Base64StdDecoding ¶ added in v0.0.17
Base64StdDecoding ...
func Base64StdEncoding ¶ added in v0.0.17
Base64StdEncoding ...
func Base64UrlDecoding ¶ added in v0.0.17
Base64UrlDecoding ...
func Base64UrlEncoding ¶ added in v0.0.17
Base64UrlEncoding ...
func BytesToString ¶ added in v0.0.17
BytesToString converts byte to a string
func Close ¶
Close is a Go function that takes an io.Closer as a parameter and closes it.
The parameter `f` is the io.Closer that needs to be closed. This function does not return anything.
func Copy ¶ added in v0.0.13
Copy copies the contents of the file at the given source path to the destination path.
Parameters: - dst: the destination path where the file will be copied to. - src: the source path of the file to be copied.
Returns: - error: an error if the file copy operation fails.
func CopyFile ¶ added in v0.0.13
CopyFile copies the contents of the file at the given source path to the destination path.
Parameters: - dst: the destination path where the file will be copied to. - src: the source path of the file to be copied.
Returns: - error: an error if the file copy operation fails.
func CreateEmptyFile ¶ added in v0.0.17
CreateEmptyFile creates an empty file at the given path. if the file already exists, it will clean content
func DirHasPrefix ¶ added in v0.0.13
DirHasPrefix checks if the directory path 's' has a prefix 'prefix'.
It takes in three parameters: - s (string): The directory path to check. - prefix (string): The prefix to compare against the directory path. - pathSeparator (rune): The path separator used in the directory path.
It returns a boolean value indicating whether the directory path has the specified prefix.
func FormatTime ¶
func FormatTime[T constraints.Float | constraints.Integer](sec T, nsec T) string
FormatTime format time use TimeFormatString layout
func GetCurrentDirectory ¶
func GetCurrentDirectory() string
GetCurrentDirectory return current execute file directory
func InSlice ¶ added in v0.0.17
func InSlice[T comparable](need T, arr []T) bool
InSlice check value in []T
func IsNumber ¶
IsNumber checks if the given string is a number.
Parameters: - s: the string to be checked.
Returns: - bool: true if the string is a number, false otherwise.
func JSONMarshalByte ¶
func JSONMarshalByte(v interface{}) []byte
JSONMarshalByte ignore error, return JSON.Marshal []byte()
func JSONMarshalString ¶
func JSONMarshalString(v interface{}) string
JSONMarshalString ignore error,return JSON.Marshal string
func Md5 ¶
Md5 calculates the MD5 hash of the input string.
It takes a string parameter and returns the MD5 hash as a string.// Md5 calculates the MD5 hash of the input string.
It takes a string parameter and returns the MD5 hash as a string.
func Md5File ¶
Md5File calculates the MD5 hash of a file specified by the filePath parameter.
It takes a string filePath parameter and returns the MD5 hash as a string and an error.
func RandomString ¶
RandomString random a string
func RandomStringWithComplex ¶ added in v0.0.16
func RandomStringWithDigital ¶ added in v0.0.16
func RandomStringWithGeneral ¶ added in v0.0.16
func RandomStringWithLowercase ¶ added in v0.0.16
func RandomStringWithMajuscule ¶ added in v0.0.16
func ReCreateDirectory ¶ added in v0.0.14
ReCreateDirectory removes the directory at the given path and creates a new empty directory at the same path.
Parameters: - dir: the path of the directory to be removed and recreated.
Returns: - error: an error if any occurred during the removal or creation of the directory.
func RemoveLastSeparator ¶ added in v0.0.14
RemoveLastSeparator removes the last separator from the given path string.
Parameters: - path: the path string from which the last separator needs to be removed.
Returns: - string: the modified path string with the last separator removed.
func RemoveSameFromStringSlice ¶
RemoveSameFromStringSlice remove []string same element Deprecated: use SliceTrimSame replace
func ReverseString ¶ added in v0.0.17
ReverseString reverse string
func StringToBytes ¶ added in v0.0.17
StringToBytes converts string to a byte slice.
func SubString ¶ added in v0.0.17
SubString returns a substring of 's' starting from 'pos' and optionally ending at 'to'. If 'pos' is out of bounds, it returns the original string.
func Unzip ¶ added in v0.0.13
func Unzip(ctx context.Context, filename string, saveAs string, handler func(file **zip.File)) error
Unzip unzip zip file
func UnzipGBKHandler ¶ added in v0.0.13
func XMLMarshalByte ¶ added in v0.0.6
func XMLMarshalByte(v interface{}) []byte
XMLMarshalByte ignore error, return xml.Marshal []byte()
func XMLMarshalString ¶ added in v0.0.6
func XMLMarshalString(v interface{}) string
XMLMarshalString ignore error,return xml.Marshal string
func Zip ¶ added in v0.0.13
Zip compresses the specified files or dirs to zip archive. If a path is a dir don't need to specify the trailing path separator. For example calling Zip("archive.zip", "dir", "csv/baz.csv") will get archive.zip and the content of which is baz.csv dir ├── bar.txt └── foo.txt Note that if a file is a symbolic link it will be skipped.
Types ¶
type DownloadFile ¶ added in v0.0.14
type DownloadFile struct {
// contains filtered or unexported fields
}
func (*DownloadFile) DisableCreateDirectory ¶ added in v0.0.14
func (d *DownloadFile) DisableCreateDirectory()
func (*DownloadFile) DownloadFromUrl ¶ added in v0.0.14
DownloadFromUrl download from url
func (*DownloadFile) GetFilename ¶ added in v0.0.14
func (d *DownloadFile) GetFilename() string
GetFilename get filename
func (*DownloadFile) SaveAsDirectory ¶ added in v0.0.14
func (d *DownloadFile) SaveAsDirectory(directory string)
SaveAsDirectory save as directory, only directory
func (*DownloadFile) SaveAsFilename ¶ added in v0.0.14
func (d *DownloadFile) SaveAsFilename(filename string)
SaveAsFilename save as filename, only filename
func (*DownloadFile) Timeout ¶ added in v0.0.14
func (d *DownloadFile) Timeout(timeout time.Duration)
Timeout set timeout
type FTP ¶ added in v0.0.14
type FTP struct { // connect info FTPAddress string FTPUsername string FTPPassword string FTPTimeout time.Duration // contains filtered or unexported fields }
FTP ftp client
func (*FTP) ChangeDir ¶ added in v0.0.14
ChangeDir changes the directory on the FTP server.
It takes a context.Context and a path string as parameters and returns an error.
func (*FTP) Close ¶ added in v0.0.14
Close closes the FTP connection.
It returns an error if there was a problem quitting the FTP connection.
func (*FTP) Connect ¶ added in v0.0.14
Connect establishes a connection to an FTP server using the provided context.
It takes a context.Context as a parameter and returns an error.
func (*FTP) Download ¶ added in v0.0.14
func (w *FTP) Download(ctx context.Context, path, saveAsDirectory string, saveAsFilename ...string) (err error)
Download downloads a file from an FTP server and saves it to a specified directory.
Parameters:
- ctx: The context.Context used for the download request.
- path: The path of the file to download from the FTP server.
- saveAsDirectory: The directory where the downloaded file will be saved.
- saveAsFilename: (Optional) The name of the file to save as. If not provided, the original filename will be used.
Returns: - err: An error if the download or file operations fail.
func (*FTP) GetServerConn ¶ added in v0.0.14
func (w *FTP) GetServerConn() *ftp.ServerConn
GetServerConn get ftp server connection
type PaginationData ¶
type PaginationData struct { Total int64 // total record Page int64 // current page PageSize int64 // show size every page PageNums int64 // show digital numbers on page FirstPage int64 // first page LastPage int64 // last page PreviousPage int64 // previous page NextPage int64 // next page TotalPage int64 // total page Pages []int64 // pages }
PaginationData pagination data
func Pagination ¶
func Pagination(total, page, pageSize int64, pageNum int64) (pg *PaginationData)
Pagination calculate total record page current page pageSize show size every page pagesNum show digital numbers on page
type TSMap ¶ added in v0.0.7
type TSMap[K, T any] struct { // contains filtered or unexported fields }
TSMap thread safe map
func (*TSMap[K, T]) Delete ¶ added in v0.0.18
func (m *TSMap[K, T]) Delete(key K)
Delete deletes the value for a key.
func (*TSMap[K, T]) Load ¶ added in v0.0.7
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*TSMap[K, T]) LoadAndDelete ¶ added in v0.0.7
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*TSMap[K, T]) LoadOrStore ¶ added in v0.0.7
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*TSMap[K, T]) Range ¶ added in v0.0.7
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.
type TSSlice ¶ added in v0.0.12
type TSSlice[T any] struct { // contains filtered or unexported fields }
TSSlice thread safe slice
func NewTSSlice ¶ added in v0.0.12
NewTSSlice new thread safe slice object