common

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KiB byteSize = 1 << (10 * iota)
	MiB
	GiB
	TiB
	PiB
	EiB
	ZiB
	YiB
)
View Source
const (
	JSONFormat  = "json"
	NoneFormat  = "none"
	TableFormat = "table"
	TomlFormat  = "toml"
	YamlFormat  = "yaml"
)
View Source
const (
	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 ByteSize

func ByteSize(i any) string

ByteSize return byte size string from giving value.

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

Convert crlf to lf.

func Examples

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

Return the string with yellow color and prefix from the given string.

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 IsCIDR added in v0.14.5

func IsCIDR(i string) bool

func IsDarwin added in v0.14.5

func IsDarwin() bool

func IsDomain added in v0.14.5

func IsDomain(i any) bool

If i is a domain return true.

func IsFile added in v0.14.5

func IsFile(f string) bool

If f is a valid path return true.

func IsIP added in v0.14.5

func IsIP(i string) bool

If i is a ipv address return true.

func IsIPv4 added in v0.14.5

func IsIPv4(i string) bool

If i is a ipv4 address return true.

func IsIPv4CIDR added in v0.14.5

func IsIPv4CIDR(i string) bool

func IsIPv6 added in v0.14.5

func IsIPv6(i string) bool

If i is a ipv6 address return true.

func IsIPv6CIDR added in v0.14.5

func IsIPv6CIDR(i string) bool

func IsURL added in v0.14.5

func IsURL(u string) bool

If u is a valid url return true.

func IsWindows added in v0.14.5

func IsWindows() bool

func NewPrinter added in v0.14.4

func NewPrinter() *printer

func ReadQRCode added in v0.1.7

func ReadQRCode(filename string) (string, error)

func SliceStringToInterface added in v0.9.4

func SliceStringToInterface(s []string) []any

Return the slice interface from the given slice string.

func SliceStringToString added in v0.9.4

func SliceStringToString(s []string, args ...string) string

Return the string from the given slice.

func SliceStringToStringNoSpaces added in v0.11.5

func SliceStringToStringNoSpaces(s []string, args ...string) string

Return the string without spaces from the given slice.

func StringRemoveSpaces added in v0.11.5

func StringRemoveSpaces(s string) string

Return string without spaces from the given string.

func Usage added in v0.2.1

func Usage(s string) string

Return the string with green color from the given string.

Types

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