utils

package
v6.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: Apache-2.0, MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// for some specific platform, it could be useful if we provide some specific data/information, so let's us mark them first
	PLATFORM_ALL          = PREPARED_PLATFORM_MARK(-1)
	PLATFORM_NOT_PROVIDED = PREPARED_PLATFORM_MARK(iota)
	PLATFORM_LINUX_AMD64
	PLATFORM_LINUX_ARM64
	PLATFORM_MACOS_AMD64
	PLATFORM_MACOS_ARM64
	PLATFORM_ANDROID_ARM64
	PLATFORM_WINDOWS_AMD64
	PLATFORM_WINDOWS_X86
)
View Source
const (
	UNKNOWN = Encoding(iota)
	UTF8
	GBK
)

Variables

View Source
var PLATFORM_MARK_FOR_PREPARED = PLATFORM_NOT_PROVIDED
View Source
var PLATFORM_NAME_STR = runtime.GOOS + "_" + runtime.GOARCH
View Source
var PktIDInvMapping map[int]string
View Source
var PktIDMapping map[string]int
View Source
var PktIDNames []string

Functions

func AutoConvertTextToUtf8

func AutoConvertTextToUtf8(data []byte) (utf8Data []byte, err error)

func CanTrigger

func CanTrigger(ss []string, triggers []string, allowNoSpace bool, removeColor bool) (bool, []string)

func Compact

func Compact(cmd string) []string

func Copy

func Copy(srcFile, dstFile string) error

func CopyDirectory

func CopyDirectory(scrDir, dest string) error
func CopySymLink(source, dest string) error

func CreateIfNotExists

func CreateIfNotExists(dir string, perm os.FileMode) error

func DownloadMicroContent

func DownloadMicroContent(sourceUrl string) ([]byte, error)

func DownloadSmallContent

func DownloadSmallContent(sourceUrl string) ([]byte, error)

func Exists

func Exists(filePath string) bool

func FormatByReplacingOccurrences

func FormatByReplacingOccurrences(tmp string, replacements map[string]interface{}) string

func GBKTextToUTF8Text

func GBKTextToUTF8Text(gbkText []byte) (utf8Text []byte, err error)

func GZIPDecompress

func GZIPDecompress(src io.Reader, dst string) error

func GenerateMCColorReplacerRule

func GenerateMCColorReplacerRule() []string

func GenerateMCColorReplacerWriter

func GenerateMCColorReplacerWriter(writer io.Writer) io.Writer

func GetAvailablePort

func GetAvailablePort() (int, error)

func GetBinaryHash

func GetBinaryHash(fileData []byte) string

func GetFileData

func GetFileData(fname string) ([]byte, error)

func GetFileHash

func GetFileHash(filePath string) (string, error)

func GetFileNotFindStack

func GetFileNotFindStack(path string) (find bool, isDir bool, errStr []string)

func GetJsonData

func GetJsonData(fname string, ptr interface{}) error

func GetJsonDataWithAttachment

func GetJsonDataWithAttachment(fname string, ptr interface{}) (remapping map[string]map[string]string, err error)

func GetStringContents

func GetStringContents(s string) []string

func GetUnZipSize

func GetUnZipSize(zipFile string) (int64, error)

func InsertHead

func InsertHead[T any](elem0 T, l []T) []T

func IsDir

func IsDir(path string) bool

func IsDirEmpty

func IsDirEmpty(dir string) bool

func IsFile

func IsFile(path string) bool

func IsGBK

func IsGBK(data []byte) (isGBK bool, failAtPos int)

func IsPortAvailable

func IsPortAvailable(port int) bool

判断端口是否可以(未被占用)

func IsUtf8

func IsUtf8(data []byte) (isUtf8 bool, failAtPos int)

func MakeDirP

func MakeDirP(path string) error

func MoveDir

func MoveDir(oldPath, newPath string) (err error)

func PostWriteJsonFile

func PostWriteJsonFile(w io.Writer, mapping map[string]map[string]string)

func PreScanJsonFile

func PreScanJsonFile(data []byte, mapping map[string]map[string]string) (reducedJson []byte, err error)

func RemoveFormat

func RemoveFormat(in string) string

func SimplePrase

func SimplePrase(cmds *[]string, argNames []string, data interface{}, firstVal bool) bool

func StringToTime

func StringToTime(timeStr string) (time.Time, error)

func StringToTimeWithLocal

func StringToTimeWithLocal(timeStr string) (time.Time, error)

func TimeToString

func TimeToString(t time.Time) string

func ToPlainName

func ToPlainName(raw_name string) string

func UnZip

func UnZip(zipFile io.ReaderAt, size int64, dstDir string) error

func WriteJsonData

func WriteJsonData(fname string, data interface{}) error

func WriteJsonDataWithAttachment

func WriteJsonDataWithAttachment(fname string, data interface{}, remapping map[string]map[string]string) error

func Zip

func Zip(srcDir string, zipFile *os.File, discardFn func(filePath string, info os.FileInfo) (discard bool)) error

Types

type Encoding

type Encoding int

func GetStrCoding

func GetStrCoding(data []byte) Encoding

type MCColorReplacerWriter

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

func (*MCColorReplacerWriter) Write

func (o *MCColorReplacerWriter) Write(p []byte) (n int, err error)

type PREPARED_PLATFORM_MARK

type PREPARED_PLATFORM_MARK int

type SimpleDeployer

type SimpleDeployer struct {
	CacheFilePath      string
	TargetDeployDir    string
	SourceFileURL      string
	SourceFileMD5      string
	SourceFileMD5ByURL string
}

func (*SimpleDeployer) Deploy

func (o *SimpleDeployer) Deploy() (err error)

type WriteCounter

type WriteCounter struct {
	Total        uint64
	DownloadSize uint64
	ProgressBar  *pb.ProgressBar
}

func (WriteCounter) PrintProgress

func (wc WriteCounter) PrintProgress()

func (*WriteCounter) Write

func (wc *WriteCounter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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