tools

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MimeSniffLen sniff Length, use for detect file mime type
	MimeSniffLen = 512
)

ReaderMimeType get the io.Reader mimeType

Usage:

file, err := os.Open(filepath)
if err != nil {
	return
}
mime := ReaderMimeType(file)

Variables

View Source
var (
	DefaultDirPerm   os.FileMode = 0775
	DefaultFilePerm  os.FileMode = 0665
	OnlyReadFilePerm os.FileMode = 0444
)

perm for create dir or file

View Source
var (
	// DefaultFileFlags for create and write
	DefaultFileFlags = os.O_CREATE | os.O_WRONLY | os.O_APPEND
	// OnlyReadFileFlags open file for read
	OnlyReadFileFlags = os.O_RDONLY
)
View Source
var (
	DirExist  = IsDir
	FileExist = IsFile
	PathExist = PathExists
)

alias methods

View Source
var ImageMimeTypes = map[string]string{
	"bmp": "image/bmp",
	"gif": "image/gif",
	"ief": "image/ief",
	"jpg": "image/jpeg",

	"jpeg": "image/jpeg",
	"png":  "image/png",
	"svg":  "image/svg+xml",
	"ico":  "image/x-icon",
	"webp": "image/webp",
}

ImageMimeTypes refer net/http package

Functions

func CheckExists added in v0.9.1

func CheckExists(path string) bool

CheckExists 判断所给路径文件或文件夹是否存在

func CheckPort

func CheckPort(port int) bool

CheckPort 检测端口是否可用

func ChickIsDir added in v0.5.0

func ChickIsDir(path string) bool

ChickIsDir 判断所给路径是否为文件夹

func Compare added in v0.7.1

func Compare(a, b string) bool

Compare returns true if the first string precedes the second one according to natural order

func Decode

func Decode(in []byte, charset string) ([]byte, error)

func DecodeFileName

func DecodeFileName(headerName string, ZipFilenameEncoding string) string

func DetectUTF8 added in v0.7.1

func DetectUTF8(s string) (valid, require bool)

DetectUTF8 检测 s 是否为有效的 UTF-8 字符串,以及该字符串是否必须被视为 UTF-8 编码(即,不兼容CP-437、ASCII 或任何其他常见编码)。 来自: go\src\archive\zip\reader.go

func FileExists added in v0.9.1

func FileExists(path string) bool

FileExists reports whether the named file or directory exists.

func GbkToUtf8 added in v0.7.1

func GbkToUtf8(unknowString string) (string, error)

func GetAbsPath added in v0.9.2

func GetAbsPath(path string) string

GetAbsPath 获取绝对路径

func GetAuthor added in v0.9.2

func GetAuthor(input string) (string, bool)

func GetContentTypeByFileName added in v0.7.1

func GetContentTypeByFileName(fileName string) (contentType string)

GetContentTypeByFileName https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

func GetEncoding

func GetEncoding(charset string) (encoding.Encoding, bool)

func GetFreePort added in v0.8.9

func GetFreePort() (int, error)

GetFreePort 获取一个空闲可用的端口号

func GetIPList

func GetIPList() (IPList []string, err error)

GetIPList 获取本机IP列表

func GetImageDataBlurHash added in v0.7.1

func GetImageDataBlurHash(loadedImage []byte, components int) string

GetImageDataBlurHash 获取图片的BlurHash

func GetImageDataBlurHashImage added in v0.7.1

func GetImageDataBlurHashImage(loadedImage []byte, components int) []byte

GetImageDataBlurHashImage 获取图片的BlurHash图

func GetMainName added in v0.9.0

func GetMainName(filename string) string

GetMainName 取得无后缀的文件名

func GetOutboundIP

func GetOutboundIP() net.IP

GetOutboundIP 获取本机的首选出站IP Get preferred outbound ip of this machine

func GuessText added in v0.7.1

func GuessText(unknowString string) (string, error)

func ImageAutoCrop added in v0.7.1

func ImageAutoCrop(loadedImage []byte, energyThreshold float32) []byte

ImageAutoCrop 自动裁白边

func ImageGray added in v0.7.1

func ImageGray(loadedImage []byte) []byte

ImageGray 转换为黑白图片

func ImageResize added in v0.7.1

func ImageResize(loadedImage []byte, width int, height int) []byte

ImageResize 重设图片分辨率

func ImageResizeByHeight added in v0.7.1

func ImageResizeByHeight(loadedImage []byte, height int) []byte

ImageResizeByHeight 根据一个固定 Height 缩放图片

func ImageResizeByMaxHeight added in v0.7.1

func ImageResizeByMaxHeight(loadedImage []byte, maxHeight int) ([]byte, error)

ImageResizeByMaxHeight 设定一个图片高度上限,大于这个高度就缩放

func ImageResizeByMaxWidth added in v0.7.1

func ImageResizeByMaxWidth(loadedImage []byte, maxWidth int) ([]byte, error)

ImageResizeByMaxWidth 设定一个图片宽度上限,大于这个宽度就缩放

func ImageResizeByWidth added in v0.7.1

func ImageResizeByWidth(loadedImage []byte, width int) []byte

ImageResizeByWidth 根据一个固定宽度缩放图片

func ImageThumbnail added in v0.7.2

func ImageThumbnail(loadedImage []byte, width int, height int) []byte

ImageThumbnail 根据设定的图片大小,剪裁图片

func IsAbsPath added in v0.9.1

func IsAbsPath(aPath string) bool

IsAbsPath is abs path.

func IsDir added in v0.9.1

func IsDir(path string) bool

IsDir reports whether the named directory exists.

func IsExist added in v0.9.2

func IsExist(path string) bool

IsExist 判断文件夹或文件是否存在

func IsFile added in v0.9.1

func IsFile(path string) bool

IsFile reports whether the named file or directory exists.

func IsImageFile added in v0.9.1

func IsImageFile(path string) bool

IsImageFile check file is image file.

func IsZipFile added in v0.9.1

func IsZipFile(filepath string) bool

IsZipFile check is zip file. from https://blog.csdn.net/wangshubo1989/article/details/71743374

func LoggerToFile

func LoggerToFile(LogFilePath string, LogFileName string) gin.HandlerFunc

LoggerToFile log功能,现在还没做完

func LoggerToStdout

func LoggerToStdout() gin.HandlerFunc

func MD5file added in v0.7.1

func MD5file(fName string) string

MD5file 计算文件MD5

func MimeType added in v0.9.1

func MimeType(path string) (mime string)

MimeType get File Mime Type name. eg "image/png"

func OpenBrowser

func OpenBrowser(uri string)

OpenBrowser 打开浏览器

func PathExists added in v0.9.1

func PathExists(path string) bool

PathExists reports whether the named file or directory exists.

func PrintAllReaderURL

func PrintAllReaderURL(Port int, OpenBrowserFlag bool, PrintAllPossibleQRCode bool, ServerHost string, DisableLAN bool, enableTls bool, etcStr string)

PrintAllReaderURL 打印阅读链接

func PrintQRCode

func PrintQRCode(text string)

func ReaderMimeType added in v0.9.1

func ReaderMimeType(r io.Reader) (mime string)

func ShiftjisToUtf8 added in v0.9.5

func ShiftjisToUtf8(unknowString string) (string, error)

func Sort added in v0.7.1

func Sort(l []string)

Sort sorts a list of strings in a natural order

func ToGBK added in v0.7.1

func ToGBK(str string) (string, error)

ToGBK Convert a string encoding from UTF-8 to ShiftJIS

func ToShiftJIS added in v0.7.1

func ToShiftJIS(str string) (string, error)

ToShiftJIS Convert a string encoding from UTF-8 to ShiftJIS

Types

type SystemStatus added in v0.7.1

type SystemStatus struct {
	//CPU相关
	CPUNumLogical  int     `json:"cpu_num_logical_total"`
	CPUNumPhysical int     `json:"cpu_num_physical"`
	CPUUsedPercent float64 `json:"cpu_used_percent"`
	//内存相关
	MemoryTotal       uint64  `json:"memory_total"`
	MemoryFree        uint64  `json:"memory_free"`
	MemoryUsedPercent float64 `json:"memory_used_percent"`
	//设备描述
	Description string `json:"description"`
}

SystemStatus 服务器当前状况

func GetSystemStatus added in v0.7.1

func GetSystemStatus() SystemStatus

Jump to

Keyboard shortcuts

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