util

package
v0.0.0-...-7873db6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// BYTE 字节
	BYTE = 1 << (10 * iota)
	// KILOBYTE 千字节
	KILOBYTE
	// MEGABYTE 兆字节
	MEGABYTE
	// GIGABYTE 吉字节
	GIGABYTE
	// TERABYTE 太字节
	TERABYTE
	// PETABYTE 拍字节
	PETABYTE
	// EXABYTE 艾字节
	EXABYTE
)
View Source
const (
	// RED 红色
	RED = "\033[31m"
	// GREEN 绿色
	GREEN = "\033[32m"
	// YELLOW 黄色
	YELLOW = "\033[33m"
	// BLUE 蓝色
	BLUE = "\033[34m"
	// FUCHSIA 紫红色
	FUCHSIA = "\033[35m"
	// CYAN 青色
	CYAN = "\033[36m"
	// WHITE 白色
	WHITE = "\033[37m"
	// RESET 重置颜色
	RESET = "\033[0m"
)

Variables

This section is empty.

Functions

func Blue

func Blue(str string) string

Blue 蓝色

func Bytefmt

func Bytefmt(bytes uint64) string

Bytefmt returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:

E: Exabyte
P: Petabyte
T: Terabyte
G: Gigabyte
M: Megabyte
K: Kilobyte
B: Byte

The unit that results in the smallest number greater than or equal to 1 is always chosen.

func CheckCommandExists

func CheckCommandExists(command string) bool

CheckCommandExists 检查命令是否存在

func CheckIP

func CheckIP(ip string) bool

CheckIP 检测ipv4地址的合法性

func Contains

func Contains(a []string, x string) bool

Contains tells whether a contains x.

func ContainsObject

func ContainsObject(a []struct{ id string }, x struct{ id string }) bool

ContainsObject 查找一个元素

func Cyan

func Cyan(str string) string

Cyan 青色

func EnsureFileExists

func EnsureFileExists(path string)

EnsureFileExists 创建空文件

func ExecCommand

func ExecCommand(command string) error

ExecCommand 运行命令并实时查看运行结果

func ExecCommandWithResult

func ExecCommandWithResult(command string) string

ExecCommandWithResult 运行命令并获取结果

func Find

func Find(a []string, x string) int

Find returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func Fuchsia

func Fuchsia(str string) string

Fuchsia 紫红色

func GenPass

func GenPass(password string) (string, string)

GenPass 自动生成加密密码和显示密码 sha256.Sum224 => heximal => encryptPass base64.StdEncoding.EncodeToString => base64Pass

func GetLocalIP

func GetLocalIP() string

GetLocalIP 获取本机ipv4地址

func Green

func Green(str string) string

Green 绿色

func Input

func Input(tip string, defaultValue string) string

Input 读取终端用户输入

func InstallPack

func InstallPack(name string)

InstallPack 安装指定名字软件

func IsExists

func IsExists(path string) bool

IsExists 检测指定路径文件或者文件夹是否存在

func IsInteger

func IsInteger(input string) bool

IsInteger 判断字符串是否为整数

func LoopInput

func LoopInput(tip string, choices interface{}, singleRowPrint bool) int

LoopInput 循环输入选择, 或者直接回车退出

func OpenPort

func OpenPort(port int)

OpenPort 开通指定端口

func PortIsUse

func PortIsUse(port int) bool

PortIsUse 判断端口是否占用

func RandString

func RandString(length int) string

RandString 随机字符串

func RandomPort

func RandomPort() int

RandomPort 获取没占用的随机端口

func Red

func Red(str string) string

Red 红色

func RunWebShell

func RunWebShell(webShellPath string)

RunWebShell 运行网上的脚本

func White

func White(str string) string

White 白色

func Yellow

func Yellow(str string) string

Yellow 黄色

Types

type Any

type Any map[string]interface{}

Any 别名

type WsConnection

type WsConnection struct {
	CloseChan chan byte // 关闭通知
	// contains filtered or unexported fields
}

WsConnection 封装websocket连接

func InitWebsocket

func InitWebsocket(resp http.ResponseWriter, req *http.Request) (wsConn *WsConnection, err error)

InitWebsocket 初始化ws

func (*WsConnection) WsClose

func (wsConn *WsConnection) WsClose()

WsClose 关闭连接

func (*WsConnection) WsRead

func (wsConn *WsConnection) WsRead() (msg *WsMessage, err error)

WsRead 读取消息

func (*WsConnection) WsWrite

func (wsConn *WsConnection) WsWrite(messageType int, data []byte) (err error)

WsWrite 发送消息

type WsMessage

type WsMessage struct {
	MessageType int
	Data        []byte
}

WsMessage websocket消息

Jump to

Keyboard shortcuts

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