general

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TabLightColor = "#874BFD"
	TabDarkColor  = "#7D56F4"
)

Tab 专用

View Source
const (
	HeaderColor    = lipgloss.Color("#CCCCCC") // 表头颜色
	BorderColor    = lipgloss.Color("#6C757D") // 边框颜色
	ColumnOneColor = lipgloss.Color("#555555") // 第一列颜色

	DefaultColor = lipgloss.Color("#FFFFFF") // 默认颜色
)

Notice: NEW

View Source
const (
	Name    string = "Wocker"                 // 程序名
	Version string = "v0.0.1"                 // 程序版本
	Project string = "github.com/yhyj/wocker" // 项目地址
)

Variables

View Source
var (
	FgBlackText        = color.FgBlack.Render        // 前景色 - 黑色
	FgWhiteText        = color.FgWhite.Render        // 前景色 - 白色
	FgLightWhiteText   = color.FgLightWhite.Render   // 前景色 - 亮白色
	FgGrayText         = color.FgGray.Render         // 前景色 - 灰色
	FgRedText          = color.FgRed.Render          // 前景色 - 红色
	FgLightRedText     = color.FgLightRed.Render     // 前景色 - 亮红色
	FgGreenText        = color.FgGreen.Render        // 前景色 - 绿色
	FgLightGreenText   = color.FgLightGreen.Render   // 前景色 - 亮绿色
	FgYellowText       = color.FgYellow.Render       // 前景色 - 黄色
	FgLightYellowText  = color.FgLightYellow.Render  // 前景色 - 亮黄色
	FgBlueText         = color.FgBlue.Render         // 前景色 - 蓝色
	FgLightBlueText    = color.FgLightBlue.Render    // 前景色 - 亮蓝色
	FgMagentaText      = color.FgMagenta.Render      // 前景色 - 品红
	FgLightMagentaText = color.FgLightMagenta.Render // 前景色 - 亮品红
	FgCyanText         = color.FgCyan.Render         // 前景色 - 青色
	FgLightCyanText    = color.FgLightCyan.Render    // 前景色 - 亮青色

	BgBlackText        = color.BgBlack.Render        // 背景色 - 黑色
	BgWhiteText        = color.BgWhite.Render        // 背景色 - 白色
	BgLightWhiteText   = color.BgLightWhite.Render   // 背景色 - 亮白色
	BgGrayText         = color.BgGray.Render         // 背景色 - 灰色
	BgRedText          = color.BgRed.Render          // 背景色 - 红色
	BgLightRedText     = color.BgLightRed.Render     // 背景色 - 亮红色
	BgGreenText        = color.BgGreen.Render        // 背景色 - 绿色
	BgLightGreenText   = color.BgLightGreen.Render   // 背景色 - 亮绿色
	BgYellowText       = color.BgYellow.Render       // 背景色 - 黄色
	BgLightYellowText  = color.BgLightYellow.Render  // 背景色 - 亮黄色
	BgBlueText         = color.BgBlue.Render         // 背景色 - 蓝色
	BgLightBlueText    = color.BgLightBlue.Render    // 背景色 - 亮蓝色
	BgMagentaText      = color.BgMagenta.Render      // 背景色 - 品红
	BgLightMagentaText = color.BgLightMagenta.Render // 背景色 - 亮品红
	BgCyanText         = color.BgCyan.Render         // 背景色 - 青色
	BgLightCyanText    = color.BgLightCyan.Render    // 背景色 - 亮青色

	InfoText      = color.Info.Render      // Info 文本
	NoteText      = color.Note.Render      // Note 文本
	LightText     = color.Light.Render     // Light 文本
	ErrorText     = color.Error.Render     // Error 文本
	DangerText    = color.Danger.Render    // Danger 文本
	NoticeText    = color.Notice.Render    // Notice 文本
	SuccessText   = color.Success.Render   // Success 文本
	CommentText   = color.Comment.Render   // Comment 文本
	PrimaryText   = color.Primary.Render   // Primary 文本
	WarnText      = color.Warn.Render      // Warn 文本
	QuestionText  = color.Question.Render  // Question 文本
	SecondaryText = color.Secondary.Render // Secondary 文本
)
View Source
var (
	ReferenceNotExistMessage = "Reference does not exist"      // 输出文本 - 引用不存在
	NoSuchImageMessage       = "No such image"                 // 输出文本 - 无此镜像
	NoSuchVolumeMessage      = "No such volume"                // 输出文本 - 无此存储卷
	NotVolumeArchiveMessage  = "Not a volume archive file"     // 输出文本 - 不是存储卷存档
	VolumeExistMessage       = "Volume already exists"         // 输出文本 - 存储卷已存在
	SpecifyMessage           = "Please specify the %s to %s\n" // 输出文本 - 请求指示
)
View Source
var (
	HeaderStyle = renderer.NewStyle().Align(lipgloss.Center).Padding(0, 1).Bold(true).Foreground(HeaderColor) // 表头样式
	BorderStyle = renderer.NewStyle().Foreground(BorderColor)                                                 // 边框样式
	CellStyle   = renderer.NewStyle().Align(lipgloss.Center).Padding(0, 1).Bold(false)                        // 单元格样式

)
View Source
var (
	GitCommitHash string = "Unknown" // Git 提交 Hash
	BuildTime     string = "Unknown" // 编译时间
	BuildBy       string = "Unknown" // 编译者
)
View Source
var (
	ErrorInfoFlag = "•" // 身份符号 - 报错信息
)

Functions

func CreateFolder

func CreateFolder(folderPath string) error

CreateFolder 创建文件夹

参数:

  • folderPath: 文件夹路径

返回:

  • 错误信息

func DeleteFile

func DeleteFile(filePath string) error

DeleteFile 删除文件,如果目标是文件夹则包括其下所有文件

参数:

  • filePath: 文件路径

返回:

  • 错误信息

func EmptyFile

func EmptyFile(filePath string) error

EmptyFile 清空文件内容,文件不存在则创建

参数:

  • filePath: 文件路径

返回:

  • 错误信息

func FaintContains

func FaintContains(slice []string, target string, length int) bool

FaintContains 判断字符串切片中是否包含指定字符串

  • 该方法为模糊匹配,即指定字符串前 length 位与切片中的字符串前 length 位匹配成功即可

参数:

  • slice: 字符串切片
  • target: 指定字符串
  • length: 指定字符串前 length 位作为判断依据

返回:

  • 布尔值

func FileExist

func FileExist(filePath string) bool

FileExist 判断文件是否存在

参数:

  • filePath: 文件路径

返回:

  • 文件存在返回 true,否则返回 false

func GetCallerInfo

func GetCallerInfo() (string, int)

GetCallerInfo 获取调用者信息

返回:

  • 调用者所在文件名(不带后缀)
  • 调用者所在行号

func GoToFolder

func GoToFolder(folderPath string) error

GoToFolder 进到指定文件夹

参数:

  • folderPath: 文件夹路径

返回:

  • 错误信息

func Human

func Human(size float64, initialUnit string) (float64, string)

Human 存储数据转换为人类可读的格式

参数:

  • size: 需要转换的存储数据
  • initialUnit: 初始单位

返回:

  • 转换后的数据
  • 转换后的单位

func ListFolderFiles

func ListFolderFiles(folderPath string) ([]string, error)

ListFolderFiles 列出指定路径下的所有文件

参数:

  • folderPath: 文件夹路径

返回:

  • 文件列表
  • 错误信息

func ListImages

func ListImages() ([]image.Summary, error)

ListImages 列出所有 image

  • 功能与命令 `docker images` 一样,但显示效果不一样

返回:

  • image 列表
  • 错误信息

func ListVolumes

func ListVolumes() (volume.ListResponse, error)

ListVolumes 列出所有 volume

  • 功能与命令 `docker volume ls` 一样,但显示效果不一样

返回:

  • volume 列表
  • 错误信息

func LoadImage

func LoadImage(archiveFile string) (bool, []string, error)

LoadImage 从存档文件加载 image

  • 功能与命令 `docker load -i <archiveFile>` 一样

参数:

  • archiveFile: 存档文件

返回:

  • docker service 是否返回错误信息
  • docker service 的返回信息
  • 错误信息

func LoadVolume

func LoadVolume(newVolumeName string, filePath string, archiveFile string) error

LoadVolume 从存档文件加载 volume

  • 功能与命令 `docker run --rm -v <newVolumeName>:/volume -v <filePath>:/backup busybox tar xzf /backup/<archiveFile> -C /volume` 一样

参数:

  • newVolumeName: 要创建的 volume 名
  • filePath: 存档文件路径
  • archiveFile: 存档文件名

返回:

  • 错误信息

func ProgramInfo

func ProgramInfo() map[string]string

ProgramInfo 返回程序信息

返回:

  • 程序信息

func ReCreateFile

func ReCreateFile(filePath string) (*os.File, error)

ReCreateFile 创建文件,包括其父目录,如果文件存在则重建

参数:

  • file: 文件路径

返回:

  • 错误信息

func SaveImage

func SaveImage(imageName string, archiveFile string) error

SaveImage 将指定 image 保存到存档文件

  • 功能与命令 `docker save <imageName> -o <archiveFile>` 一样

参数:

  • imageName: image 的 Repository(:Tag) 或 ID
  • archiveFile: 存档文件

返回:

  • 错误信息

func SaveVolume

func SaveVolume(volumeName string, filePath string, archiveFile string) error

SaveVolume 将指定 volume 保存到存档文件

  • 功能与命令 `docker run --rm -v <volumeName>:/volume -v <filePath>:/backup busybox tar czf /backup/<archiveFile> -C /volume .` 一样

参数:

  • volumeName: volume 名
  • filePath: 存档文件路径
  • archiveFile: 存档文件名

返回:

  • 错误信息

func SliceContains

func SliceContains(slice []string, target string) bool

SliceContains 判断字符串切片中是否包含指定字符串

参数:

  • slice: 字符串切片
  • target: 指定字符串

返回:

  • 布尔值

func UnixTime2TimeString

func UnixTime2TimeString(unixTime int64) string

UnixTime2TimeString Unix 时间戳转换为字符串格式

参数:

  • timeStamp: Unix 时间戳

返回:

  • 格式化的 Unix 时间戳字符串

func WriteFile

func WriteFile(filePath, content, mode string) error

WriteFile 写入内容到文件,文件不存在则创建,不自动换行

参数:

  • filePath: 文件路径
  • content: 内容
  • mode: 写入模式,追加('a', O_APPEND, 默认)或覆盖('t', O_TRUNC)

返回:

  • 错误信息

func WriteFileWithNewLine

func WriteFileWithNewLine(filePath, content, mode string) error

WriteFileWithNewLine 写入内容到文件,文件不存在则创建,自动换行

参数:

  • filePath: 文件路径
  • content: 写入内容
  • mode: 写入模式,追加('a', O_APPEND, 默认)或覆盖('t', O_TRUNC)

返回:

  • 错误信息

Types

type LoadResponse

type LoadResponse struct {
	Stream string `json:"stream"`
	Error  string `json:"error"`
}

Jump to

Keyboard shortcuts

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