Documentation ¶
Index ¶
- Constants
- Variables
- func ClientIP(r *http.Request) string
- func CopyDir(src, dst string) error
- func CopyFile(src, dst string) error
- func CopyWithBuffer(dst io.Writer, src io.Reader) (written int64, err error)
- func CopyWithBufferN(dst io.Writer, src io.Reader, n int64) (written int64, err error)
- func CopyWithCtx(ctx context.Context, out io.Writer, in io.Reader, size int64, ...) error
- func CreateNestedDirectory(path string) error
- func CreateNestedFile(path string) (*os.File, error)
- func CreateTempFile(r io.Reader, size int64) (*os.File, error)
- func EncodePath(path string, all ...bool) string
- func Exists(name string) bool
- func Ext(path string) string
- func FixAndCleanPath(path string) string
- func GetActualMountPath(mountPath string) string
- func GetFileType(filename string) int
- func GetFullPath(mountPath, path string) string
- func GetMD5EncodeStr(data string) string
- func GetMimeType(name string) string
- func GetNoneEmpty(strArr ...string) string
- func GetObjType(filename string, isDir bool) int
- func HashData(hashType *HashType, data []byte, params ...any) string
- func HashFile(hashType *HashType, file io.ReadSeeker, params ...any) (string, error)
- func HashReader(hashType *HashType, reader io.Reader, params ...any) (string, error)
- func InjectQuery(raw string, query url.Values) (string, error)
- func IsBalance(str string) bool
- func IsBool(bs ...bool) bool
- func IsCanceled(ctx context.Context) bool
- func IsEmailFormat(email string) bool
- func IsLocalIP(ip net.IP) bool
- func IsLocalIPAddr(ip string) bool
- func IsSubPath(path string, subPath string) bool
- func JoinBasePath(basePath, reqPath string) (string, error)
- func LimitWriter(w io.Writer, limit int64) io.Writer
- func MappingName(name string) string
- func Max[T constraints.Ordered](a, b T) T
- func MergeErrors(errs ...error) error
- func MergeMap(mObj ...map[string]interface{}) map[string]interface{}
- func Min[T constraints.Ordered](a, b T) T
- func MustParseCNTime(str string) time.Time
- func MustSliceConvert[S any, D any](srcS []S, convert func(src S) D) []D
- func NewDebounce(interval time.Duration) func(f func())
- func NewDebounce2(interval time.Duration, f func()) func()
- func NewLimitReadCloser(reader io.Reader, close CloseFunc, limit int64) io.ReadCloser
- func NewReadCloser(reader io.Reader, close CloseFunc) io.ReadCloser
- func NewThrottle(interval time.Duration) func(func())
- func NewThrottle2(interval time.Duration, fn func()) func()
- func PathAddSeparatorSuffix(path string) string
- func PathEqual(path1, path2 string) bool
- func Retry(attempts int, sleep time.Duration, f func() error) (err error)
- func SafeAtob(data string) (string, error)
- func SliceAllContains[T comparable](arr []T, vs ...T) bool
- func SliceContains[T comparable](arr []T, v T) bool
- func SliceConvert[S any, D any](srcS []S, convert func(src S) (D, error)) ([]D, error)
- func SliceEqual[T comparable](a, b []T) bool
- func SliceFilter[T any](arr []T, filter func(src T) bool) []T
- func SliceMeet[T1, T2 any](arr []T1, v T2, meet func(item T1, v T2) bool) bool
- func SliceReplace[T any](arr []T, replace func(src T) T)
- func SymlinkOrCopyFile(src, dst string) error
- func TokenSource(fn func() (*oauth2.Token, error)) oauth2.TokenSource
- func WriteJsonToFile(dst string, data interface{}, std ...bool) bool
- type CloseFunc
- type Closers
- type ClosersIF
- type HashInfo
- type HashType
- type MultiHasher
- type MultiReadable
- type ReadCloser
Constants ¶
const ( KB = 1 << (10 * (iota + 1)) MB GB TB )
Variables ¶
var ( // MD5 indicates MD5 support MD5 = RegisterHash("md5", "MD5", 32, md5.New) // SHA1 indicates SHA-1 support SHA1 = RegisterHash("sha1", "SHA-1", 40, sha1.New) // SHA256 indicates SHA-256 support SHA256 = RegisterHash("sha256", "SHA-256", 64, sha256.New) )
var CNLoc = time.FixedZone("UTC", 8*60*60)
var DEC = map[string]string{
"-": "+",
"_": "/",
".": "=",
}
var ErrUnsupported = errors.New("hash type not supported")
ErrUnsupported should be returned by filesystem, if it is requested to deliver an unsupported hash type.
var IoBuffPool = &sync.Pool{ New: func() interface{} { return make([]byte, 32*1024*2) }, }
var Json = json.ConfigCompatibleWithStandardLibrary
var Log = log.New()
var (
Supported []*HashType
)
Functions ¶
func CopyWithBufferN ¶
func CopyWithCtx ¶
func CopyWithCtx(ctx context.Context, out io.Writer, in io.Reader, size int64, progress func(percentage float64)) error
CopyWithCtx slightly modified function signature: - context has been added in order to propagate cancellation - I do not return the number of bytes written, has it is not useful in my use case
func CreateNestedDirectory ¶
CreateNestedDirectory create nested directory
func CreateNestedFile ¶
CreateNestedFile create nested file
func CreateTempFile ¶
CreateTempFile create temp file from io.ReadCloser, and seek to 0
func EncodePath ¶
func FixAndCleanPath ¶
FixAndCleanPath The upper layer of the root directory is still the root directory. So ".." And "." will be cleared for example 1. ".." or "." => "/" 2. "../..." or "./..." => "/..." 3. "../.x." or "./.x." => "/.x." 4. "x//\\y" = > "/z/x"
func GetActualMountPath ¶
GetActualMountPath remove balance suffix
func GetFullPath ¶
func GetMD5EncodeStr ¶
func GetMimeType ¶
func GetNoneEmpty ¶
GetNoneEmpty returns the first non-empty string, return empty if all empty
func GetObjType ¶
func HashReader ¶
HashReader get hash of one hashType from a reader
func IsCanceled ¶
func IsEmailFormat ¶
func IsLocalIPAddr ¶
func JoinBasePath ¶
func MappingName ¶
func Max ¶
func Max[T constraints.Ordered](a, b T) T
func MergeErrors ¶
func Min ¶
func Min[T constraints.Ordered](a, b T) T
func MustParseCNTime ¶
func MustSliceConvert ¶
func NewDebounce ¶
func NewDebounce2 ¶
func NewLimitReadCloser ¶
func NewReadCloser ¶
func NewReadCloser(reader io.Reader, close CloseFunc) io.ReadCloser
func NewThrottle ¶
func NewThrottle2 ¶
func PathAddSeparatorSuffix ¶
PathAddSeparatorSuffix Add path '/' suffix for example /root => /root/
func SliceAllContains ¶
func SliceAllContains[T comparable](arr []T, vs ...T) bool
SliceAllContains check if slice all contains elements
func SliceContains ¶
func SliceContains[T comparable](arr []T, v T) bool
SliceContains check if slice contains element
func SliceConvert ¶
SliceConvert convert slice to another type slice
func SliceEqual ¶
func SliceEqual[T comparable](a, b []T) bool
SliceEqual check if two slices are equal
func SliceFilter ¶
func SliceReplace ¶
func SliceReplace[T any](arr []T, replace func(src T) T)
func SymlinkOrCopyFile ¶
SymlinkOrCopyFile symlinks a file or copy if symlink failed
func TokenSource ¶
func TokenSource(fn func() (*oauth2.Token, error)) oauth2.TokenSource
func WriteJsonToFile ¶
WriteJsonToFile write struct to json file
Types ¶
type Closers ¶
type Closers struct {
// contains filtered or unexported fields
}
func EmptyClosers ¶
func EmptyClosers() Closers
func NewClosers ¶
func (*Closers) AddClosers ¶
func (*Closers) GetClosers ¶
type HashInfo ¶
type HashInfo struct {
// contains filtered or unexported fields
}
A HashInfo contains hash string for one or more hashType
func FromString ¶
func NewHashInfo ¶
func NewHashInfoByMap ¶
type HashType ¶
HashType indicates a standard hashing algorithm
func RegisterHash ¶
RegisterHash adds a new Hash to the list and returns its Type
func RegisterHashWithParam ¶
func (*HashType) MarshalJSON ¶
func (*HashType) MarshalText ¶
type MultiHasher ¶
type MultiHasher struct {
// contains filtered or unexported fields
}
A MultiHasher will construct various hashes on all incoming writes.
func NewMultiHasher ¶
func NewMultiHasher(types []*HashType) *MultiHasher
NewMultiHasher will return a hash writer that will write the requested hash types.
func (*MultiHasher) GetHashInfo ¶
func (m *MultiHasher) GetHashInfo() *HashInfo
func (*MultiHasher) Size ¶
func (m *MultiHasher) Size() int64
Size returns the number of bytes written
type MultiReadable ¶
type MultiReadable struct {
// contains filtered or unexported fields
}
func NewMultiReadable ¶
func NewMultiReadable(reader io.Reader) *MultiReadable
func (*MultiReadable) Close ¶
func (mr *MultiReadable) Close() error
func (*MultiReadable) Reset ¶
func (mr *MultiReadable) Reset() error