common

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileModeROwner os.FileMode = 0600
	FileModeRAll   os.FileMode = 0644
)
View Source
const (
	HashMd5        = "md5"
	HashSha1       = "sha1"
	HashSha224     = "sha224"
	HashSha256     = "sha256"
	HashSha384     = "sha384"
	HashSha512     = "sha512"
	HashSha512_224 = "sha512_224"
	HashSha512_256 = "sha512_256"
)
View Source
const (
	IndentTwoSpaces = "  "

	RepoOwner = "linzeyan"
	RepoName  = "ops-cli"

	UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
)

Variables

View Source
var (
	ErrConfigContent = errors.New("config content is incorrect")
	ErrConfigTable   = errors.New("table not found in the config")
	ErrFailedInitial = errors.New("initial failed")
	ErrIllegalPath   = errors.New("illegal file path")
	ErrInvalidArg    = errors.New("invalid argument")
	ErrInvalidFlag   = errors.New("required flag(s) not set")
	ErrInvalidIP     = errors.New("invalid IP")
	ErrInvalidFile   = errors.New("invalid file format")
	ErrInvalidToken  = errors.New("invalid token")
	ErrInvalidURL    = errors.New("invalid URL")
	ErrResponse      = errors.New("response error")
	ErrStatusCode    = errors.New("status code is not 200")
)
View Source
var (
	Context = context.Background()
	TimeNow = time.Now().Local()
)

Functions

func Config

func Config(path, table string) map[string]any

Get secret token and other settings from config.

func Dos2Unix added in v0.1.7

func Dos2Unix(filename string) error

func Examples

func Examples(example string, cmdName ...string) string

Print string with color.

func GenerateQRCode added in v0.1.7

func GenerateQRCode(content string, size int, dest string) error

Generate QR code by giving content.

func HTTPRequestContent

func HTTPRequestContent(url string, config ...HTTPConfig) ([]byte, error)

HttpRequestContent make a simple request to url, and return response body, default request method is get.

func HTTPRequestContentGB18030 added in v0.1.7

func HTTPRequestContentGB18030(url string, body io.Reader, methods ...string) ([]byte, error)

Same as HttpRequestContent, but read content in GB18030 format.

func HTTPRequestRedirectURL added in v0.1.7

func HTTPRequestRedirectURL(uri string) (string, error)

Return redirect url.

func HashAlgorithm

func HashAlgorithm(alg string) hash.Hash

func ReadQRCode added in v0.1.7

func ReadQRCode(filename string) (string, error)

func Usage added in v0.2.1

func Usage(s string) string

Types

type ByteSize

type ByteSize float64
const (
	KiB ByteSize = 1 << (10 * iota)
	MiB
	GiB
	TiB
	PiB
	EiB
	ZiB
	YiB
)

func (ByteSize) String

func (b ByteSize) String() string

type HTTPConfig added in v0.3.5

type HTTPConfig struct {
	Method  string
	Body    string
	Verbose bool
	Headers string
}

Jump to

Keyboard shortcuts

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