utils

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

http://dockone.io/article/109 https://docs.docker.com/engine/api/v1.24/#2-errors https://godoc.org/github.com/docker/docker/client#FromEnv

读取指定yaml文件

有关Http协议GET和POST请求的封装 https://studygolang.com/articles/17373?fr=sidebar

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(temp string, data map[string]interface{}) (string, error)

渲染模板

func DecodeBase64

func DecodeBase64(in string) (string, error)

解密base64

func EncodeBase64

func EncodeBase64(in string) string

加密base64

func ExecCommand

func ExecCommand(cmd string) ([]byte, error)

func ExecCommandStd

func ExecCommandStd(cmd string) error

func ExecCommandString

func ExecCommandString(cmd string) (string, error)

func Get

func Get(url string) (response []byte, err error)

发送GET请求 url:请求地址 response:请求返回的内容

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetIPs

func GetIPs() (ips []string)

func GetMacAddrs

func GetMacAddrs() (macAddrs []string)

0:cf:e0:44:dd:be,enp1s0

func GetRandomSalt

func GetRandomSalt() string

return len=8 salt

func GetRandomString

func GetRandomString(len int) string

生成随机字符串

func IsBetweenAB

func IsBetweenAB(start, end string) (bool, error)

判断是否在两个时间范围内

func Jiami

func Jiami(code string) string

加密

func MD5

func MD5(text string) string

生成32位MD5

func NewDockerCLI

func NewDockerCLI(host, port, version string) *docker

func NewDockerCli

func NewDockerCli(args []string, image, cmd, workspace, reponame string) *dockerCli

func ParseIps

func ParseIps(in string) ([]string, error)

解析IP地址

func PathExists

func PathExists(path string) (bool, error)

PathExists 判断文件夹是否存在

func Post

func Post(url string, data interface{}, contentType string) (result []byte, err error)

发送POST请求 url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json content:请求放回的内容

func ReadYamlConfig

func ReadYamlConfig(path string) (interface{}, error)

指定读取yaml文件

func ScanPort

func ScanPort(host string, port int) bool

func TransformCHN

func TransformCHN(data []string) ([]int, error)

转换星期中文为数字

Types

type Cli

type Cli struct {
	IP       string //IP地址
	Username string //用户名
	Password string //密码
	Port     int    //端口号

	LastResult string //最近一次Run的结果
	// contains filtered or unexported fields
}

func New

func New(ip string, username string, password string, port ...int) *Cli

创建命令行对象 @param ip IP地址 @param username 用户名 @param password 密码 @param port 端口号,默认22

func (*Cli) Run

func (c *Cli) Run(shell string) (string, error)

执行shell @param shell shell脚本命令

func (*Cli) RunTerminal

func (c *Cli) RunTerminal(shell string, stdout, stderr io.Writer) error

执行带交互的命令

func (*Cli) SftpDownloadToLocal

func (c *Cli) SftpDownloadToLocal(localpath, remotepath string) error

下载文件

func (*Cli) SftpUploadTemplateString

func (c *Cli) SftpUploadTemplateString(data, remotepath string) error

上传文件String

func (*Cli) SftpUploadToRemote

func (c *Cli) SftpUploadToRemote(localpath, remotepath string) error

上传文件 注意: remotepath是文件路径不是文件夹路径

type LogFileWriter

type LogFileWriter struct {
	File *os.File
	//write count
	Size int64
}

func (LogFileWriter) Write

func (p LogFileWriter) Write(data []byte) (n int, err error)

Jump to

Keyboard shortcuts

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