utils

package
v3.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: AGPL-3.0 Imports: 19 Imported by: 79

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEC = map[string]string{
	"-": "+",
	"_": "/",
	".": "=",
}
View Source
var Log = log.New()

Functions

func ClientIP

func ClientIP(r *http.Request) string

func CopyDir

func CopyDir(src string, dst string) error

CopyDir Dir copies a whole directory recursively

func CopyFile

func CopyFile(src, dst string) error

CopyFile File copies a single file from src to dst

func CopyWithCtx

func CopyWithCtx(ctx context.Context, out io.Writer, in io.Reader, size int64, progress func(percentage int)) error

CopyWithCtx slightly modified function signature: - context has been added in order to propagate cancelation - I do not return the number of bytes written, has it is not useful in my use case

func CreateNestedFile

func CreateNestedFile(path string) (*os.File, error)

CreateNestedFile create nested file

func CreateTempFile

func CreateTempFile(r io.ReadCloser) (*os.File, error)

CreateTempFile create temp file from io.ReadCloser, and seek to 0

func EncodePath

func EncodePath(path string, all ...bool) string

func Exists

func Exists(name string) bool

Exists determine whether the file exists

func Ext

func Ext(path string) string

func GetActualVirtualPath

func GetActualVirtualPath(virtualPath string) string

GetActualVirtualPath remove balance suffix

func GetFileType

func GetFileType(filename string) int

GetFileType get file type

func GetMD5Encode

func GetMD5Encode(data string) string

func GetSHA1Encode

func GetSHA1Encode(data string) string

func IsBalance

func IsBalance(str string) bool

func IsCanceled

func IsCanceled(ctx context.Context) bool

func IsLocalIP

func IsLocalIP(ip net.IP) bool

func IsLocalIPAddr

func IsLocalIPAddr(ip string) bool

func LimitWriter

func LimitWriter(w io.Writer, size int64) io.Writer

func MergeMap

func MergeMap(mObj ...map[string]interface{}) map[string]interface{}

func PathEqual

func PathEqual(path1, path2 string) bool

PathEqual judge path is equal

func SafeAtob

func SafeAtob(data string) (string, error)

func SliceContains

func SliceContains[T comparable](arr []T, v T) bool

SliceContains check if slice contains element

func SliceConvert

func SliceConvert[S any, D any](srcS []S, convert func(src S) (D, error)) ([]D, error)

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 StandardizePath

func StandardizePath(path string) string

StandardizePath convert path like '/' '/root' '/a/b'

func WriteJsonToFile

func WriteJsonToFile(dst string, data interface{}) bool

WriteJsonToFile write struct to json file

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL