utils

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntityInvalid      = errors.New(`common.ENTITY_INVALID`)
	ErrFailedVerification = errors.New(`common.ENTITY_CHECK_FAILED`)
)
View Source
var GithuApi = "https://api.github.com/repos/xxl6097/go-frp-panel/releases/latest"

Functions

func AppendStringToFile

func AppendStringToFile(filePath, content string) error

func BindJSON

func BindJSON[T any](r *http.Request) (*T, error)

func ByteCountIEC added in v0.1.91

func ByteCountIEC(b uint64) string

func BytesToHexString

func BytesToHexString(bytes []byte) string

func BytesToString

func BytesToString(b []byte, r ...int) string

func CheckBinaryPack

func CheckBinaryPack(data []byte) (byte, byte, bool)

func CheckDir added in v0.1.82

func CheckDir(dirPath string) bool

func CheckVersionFromGithub

func CheckVersionFromGithub() []string

func CleanExt

func CleanExt(name string) string

func ClearDir added in v0.2.0

func ClearDir(tmpPath string) error

func ClearTmpDir added in v0.2.0

func ClearTmpDir() error

func CompareVersions

func CompareVersions(v1, v2 string) int

CompareVersions 0:相等;1:v1>v2;-1:v1<v2

func CopyFile

func CopyFile(src, dst string) error

CopyFile 使用 io.Copy 函数复制文件

func DecAES

func DecAES(data []byte, key []byte) ([]byte, error)

func Delete

func Delete(filePath string, args ...string)

func DirCheck

func DirCheck(path string) error

func Divide

func Divide(a, b int) int

func DivideAndCeil

func DivideAndCeil(a, b int) int

DivideAndCeil 函数用于进行除法并向上取整

func DownLoadBAK added in v0.1.37

func DownLoadBAK(url string, args ...string) (string, error)

func DynamicSelect

func DynamicSelect[T any](t []T, fun func(int, T) T) T

func EncAES

func EncAES(data []byte, key []byte) ([]byte, error)

func EnsureDir

func EnsureDir(path string) error

func ExtractCodeBlocks added in v0.1.55

func ExtractCodeBlocks(markdown string) []string

func FormatSize

func FormatSize(size int64) string

func GenRandByte

func GenRandByte(n int) []byte

func GetAppSpace added in v0.2.15

func GetAppSpace() (string, string, string)

func GetDataByJson

func GetDataByJson[T any](r *http.Request) (*T, error)

func GetFileNameByTime

func GetFileNameByTime() string

func GetFileNameFromUrl

func GetFileNameFromUrl(rawURL string) string

func GetFilenameFromHeader

func GetFilenameFromHeader(header http.Header) string

func GetFirstPathSegment added in v0.2.6

func GetFirstPathSegment(path string) string

GetFirstPathSegment 获取路径第一个有效段(优化实现)

func GetFuncInstance

func GetFuncInstance[T any](name string, obj interface{}) *T

func GetListeningPorts

func GetListeningPorts()

func GetMD5

func GetMD5(data []byte) ([]byte, string)

func GetPointerInstance

func GetPointerInstance[T any](name string, obj interface{}) *T

func GetSelfSize added in v0.1.68

func GetSelfSize() uint64

func GetSliceChunk

func GetSliceChunk[T any](data *[]T, start, end int) *[]T

func GetSlicePrefix

func GetSlicePrefix[T any](data *[]T, n int) *[]T

func GetSliceSuffix

func GetSliceSuffix[T any](data *[]T, n int) *[]T

func GetStrUUID

func GetStrUUID() string

func GetStructInstance

func GetStructInstance[T any](name string, obj interface{}) *T

func GetTime

func GetTime() string

func GetUUID

func GetUUID() []byte

func GetVersionByFileName added in v0.1.82

func GetVersionByFileName(filename string) string

func GithubApiReqest added in v0.2.10

func GithubApiReqest() ([]byte, error)

func HasDiskSpace added in v0.1.83

func HasDiskSpace() bool

func If

func If[T any](b bool, t, f T) T

func IsDirectoryExist

func IsDirectoryExist(dirPath string) bool

func IsExist added in v0.2.6

func IsExist(filePath string) bool

func IsLinux

func IsLinux() bool

func IsMacOs

func IsMacOs() bool

func IsPortOpen

func IsPortOpen(host string, port int, timeout time.Duration) bool

func IsURLValidAndAccessible

func IsURLValidAndAccessible(rawURL string) bool

IsURLValidAndAccessible 检查 URL 是否有效并且可访问

func IsWindows

func IsWindows() bool

IsWindows 判断是否为 Windows 系统

func IsZipOrJson

func IsZipOrJson(filename string) (isZip, isJSON bool)

IsZipOrJson 根据后缀判断文件类型(仅后缀匹配)

func MakeDir added in v0.1.91

func MakeDir(path string) error

func Max

func Max[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](a, b T) T

func Min

func Min[T int | int32 | int64 | uint | uint32 | uint64 | float32 | float64](a, b T) T

func MoveFileToDir added in v0.1.82

func MoveFileToDir(src string, dstDir string) error

func ObjectToTomlText

func ObjectToTomlText(obj interface{}) []byte

func ParseMarkdownCodeToStringArray added in v0.1.82

func ParseMarkdownCodeToStringArray(body string) []string

func PingRaw

func PingRaw(ip string) bool

func Read

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

func ReadToml

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

func RemoveSlice

func RemoveSlice[T comparable](slice []T, value T) []T

RemoveSlice 泛型删除所有匹配值的元素

func ReplaceExecutable

func ReplaceExecutable(currentPath, newPath string) error

ReplaceExecutable 替换当前可执行文件

func ReplaceNewVersionBinName

func ReplaceNewVersionBinName(filename, v string) string

func RestartProgram

func RestartProgram() error

RestartProgram 重启程序

func SaveFile

func SaveFile(file multipart.File, fileSize int64, saveFilePath string) error

func ScanIP

func ScanIP() []string

func ScanPort

func ScanPort(host string, duration time.Duration, start, end int) []int

func ScanPorts

func ScanPorts(host string, start, end int) []int

func SetFieldValue

func SetFieldValue(obj interface{}, fieldName string, value interface{}) error

SetFieldValue 使用反射给结构体的字段赋值

func ShowUpDirSize added in v0.1.83

func ShowUpDirSize()

func Shutdown

func Shutdown() error

func SignAndInstall

func SignAndInstall(newBufferBytes, oldBufferBytes []byte, newFilePath string) (string, error)

func SplitLastTwoByUnderscore added in v0.1.92

func SplitLastTwoByUnderscore(s string) []string

func SplitVersion

func SplitVersion(v string) []string

func StringContains

func StringContains(element string, data []string) bool

func StringToBytes

func StringToBytes(s string, r ...int) []byte

func TestToml

func TestToml()

func ToUpperFirst

func ToUpperFirst(s string) string

ToUpperFirst 将字符串的首字母转换为大写

func TomlTextToObject

func TomlTextToObject(tomlBytes []byte, obj interface{}) error

func Unzip

func Unzip(src, dest string) error

Unzip 函数用于解压指定的ZIP文件到指定的目标目录

func UnzipToRoot

func UnzipToRoot(zipFile, destDir string, strich bool) error

func Write

func Write(filePath string, content []byte) error

func WriteAppend

func WriteAppend(filePath string, content []byte) error

func WriteFile

func WriteFile(filePath string, data []byte) error

func WriteToml

func WriteToml(filePath string, data []byte) error

func XOR

func XOR(data []byte, key []byte) []byte

func Zip

func Zip(dir, dst string) error

Types

type GeneralResponse

type GeneralResponse struct {
	Pid int
	Msg string
}

type Node

type Node struct {
	Label    string `json:"label"`
	Value    string `json:"value"`
	FilePath string `json:"filePath"`
}

type Option

type Option struct {
	Label    string `json:"label"`
	Value    string `json:"value"`
	Children []Node `json:"children"`
}

func GetNodes

func GetNodes(dir string) []Option

func GetNodes1 added in v0.1.96

func GetNodes1(dir string) []Option

func ToTree added in v0.1.96

func ToTree(dir string, entries []string) []Option

type ProgressWriter

type ProgressWriter struct {
	TotalSize int64
	Written   int64
	Progress  float64
	Title     string
}

ProgressWriter 自定义进度写入器结构体

func (*ProgressWriter) Write

func (pw *ProgressWriter) Write(p []byte) (int, error)

Write 实现 io.Writer 接口的 Write 方法

Jump to

Keyboard shortcuts

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