utils

package
v0.0.0-...-366d0f7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package utils provides the util func

Package utils provides the util func

Package utils offer utils for file watcher

Package utils offer the some utils for certificate handling

Package utils offer the some utils for certificate handling

Package utils provides the util func

Package utils this file for password handler

Package utils provides the util func

Index

Constants

View Source
const (
	// FileMode file privilege
	FileMode = 0600
	// Size10M  bytes of 10M
	Size10M = 10 * 1024 * 1024
)
View Source
const (

	// DefaultWhiteList default white list in string
	DefaultWhiteList = "-_./~"
	// DefaultStringLength default string max length
	DefaultStringLength = 256
	// DefaultPathLength default path max length
	DefaultPathLength = 4096
)
View Source
const (

	// DefaultWriteFileMode  default file mode for write permission check
	DefaultWriteFileMode = 0022
)
View Source
const (

	// SplitFlag backup file splitflag
	SplitFlag = "\n</=--*^^||^^--*=/>"
)

Variables

This section is empty.

Functions

func CheckMode

func CheckMode(mode os.FileMode, optional ...os.FileMode) bool

CheckMode check input file mode whether includes invalid mode. For example, if read operation of group and other is forbidden, then call CheckMode(inputFileMode, 0044). All operations are forbidden for group and other, then call CheckMode(inputFileMode, 0077). Write operation is forbidden for group and other by default, with calling CheckMode(inputFileMode)

func CheckOwnerAndPermission

func CheckOwnerAndPermission(verifyPath string, mode os.FileMode, uid uint32) (string, error)

CheckOwnerAndPermission check path owner and permission

func CheckPassWordComplexity

func CheckPassWordComplexity(s []byte) error

CheckPassWordComplexity check password complexity

func CheckPath

func CheckPath(path string) (string, error)

CheckPath validate given path and return resolved absolute path

func ClientIP

func ClientIP(r *http.Request) string

ClientIP try to get the clientIP

func CopyDir

func CopyDir(src string, dst string) error

CopyDir recursively copy files

func CopyFile

func CopyFile(src, dst string) error

CopyFile copy file

func GetDriverLibPath

func GetDriverLibPath(libraryName string) (string, error)

GetDriverLibPath get driver lib path from ld config

func GetSha256Code

func GetSha256Code(data []byte) []byte

GetSha256Code return the sha256 hash bytes

func IsDir

func IsDir(path string) bool

IsDir check whether the path is a directory.

func IsExist

func IsExist(filePath string) bool

IsExist check whether the path exists, If the file is a symbolic link, the returned the final FileInfo

func IsFile

func IsFile(path string) bool

IsFile check whether the path is a file

func IsLexist

func IsLexist(filePath string) bool

IsLexist check whether the path exists, If the file is a symbolic link, the returned FileInfo describes the symbolic link

func IsNil

func IsNil(i interface{}) bool

IsNil check whether the interface is nil, including type or data is nil

func IsSoftlink(path string) (bool, error)

IsSoftlink check whether the path is softlink

func LoadFile

func LoadFile(filePath string) ([]byte, error)

LoadFile load file content

func MakeSureDir

func MakeSureDir(path string) error

MakeSureDir create directory. The last element of path should end with slash, or it will be omitted.

func MaskPrefix

func MaskPrefix(source string) string

MaskPrefix mask string prefix with ****

func PathStringChecker

func PathStringChecker(path string) (string, error)

PathStringChecker Check whether the directory string is valid

func ReadLimitBytes

func ReadLimitBytes(path string, limitLength int) ([]byte, error)

ReadLimitBytes read limit length of contents from file path

func RealDirChecker

func RealDirChecker(path string, checkParent, allowLink bool) (string, error)

RealDirChecker Check whether the directory is valid

func RealFileChecker

func RealFileChecker(path string, checkParent, allowLink bool, size int64) (string, error)

RealFileChecker Check whether the file is valid

func ReplacePrefix

func ReplacePrefix(source, prefix string) string

ReplacePrefix replace string with prefix

func ReverseString

func ReverseString(s string) string

ReverseString reverse string

func SafeChmod

func SafeChmod(path string, size int64, mode os.FileMode) error

SafeChmod after the verification is complete, run the chmod command.

func ValidatePassWord

func ValidatePassWord(userName string, passWord []byte) error

ValidatePassWord validate password

func VerifyFile

func VerifyFile(file *os.File, size int64) error

VerifyFile verify the file after it is opened.

Types

type FileWatcher

type FileWatcher struct {
	// contains filtered or unexported fields
}

FileWatcher struct file watcher

func GetFileWatcherChan

func GetFileWatcherChan(filePath string) (*FileWatcher, error)

GetFileWatcherChan get eventCh and errCh for file watcher

func NewFileWatcher

func NewFileWatcher() (*FileWatcher, error)

NewFileWatcher new FileWatcher

func (*FileWatcher) Close

func (fw *FileWatcher) Close() error

Close to close the file watcher

func (*FileWatcher) Errors

func (fw *FileWatcher) Errors() chan error

Errors get error channel

func (*FileWatcher) Events

func (fw *FileWatcher) Events() chan fsnotify.Event

Events get event channel

func (*FileWatcher) WatchFile

func (fw *FileWatcher) WatchFile(filePath string) error

WatchFile add file to watch

Jump to

Keyboard shortcuts

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