utils

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Prefix is the identifier for the Apache-specific MD5 algorithm.
	Prefix = "$apr1$"

	// Size is the size of an MD5 checksum in bytes.
	Size = 16

	// Blocksize is the blocksize of APR1 in bytes.
	Blocksize = 64

	// Rounds is the number of rounds in the big loop.
	Rounds = 1000
)

Variables

This section is empty.

Functions

func AddressRange

func AddressRange(network *net.IPNet) (net.IP, net.IP)

AddressRange returns the first and last addresses in the given CIDR range.

func Any added in v0.6.1

func Any(arrays []string, excludes ...string) string

func Append

func Append(ips []string, app string) []string

func Assert

func Assert(check bool, msg string, params ...interface{})

func Async

func Async() *async

func Base64File

func Base64File(file string) string

func CamelName

func CamelName(name string) string

下划线写法转为驼峰写法

func Catch

func Catch(fns ...func(error))

func CompileSplit2

func CompileSplit2(str, sep string) (a, b string)

func CompileSplit3

func CompileSplit3(str, sep string) (a, b, c string)

func ComposeIP

func ComposeIP(a, b net.IP) int

func Copy added in v0.5.0

func Copy(src, dest string) (err error)

func Copyto added in v0.5.0

func Copyto(src, destPath string) (string, error)

func DashName

func DashName(name string) string

func Default

func Default(args []string, index int, def string) string

func Exists

func Exists(path string) bool

func FileBytes

func FileBytes(path string) []byte

func FirstLine

func FirstLine(content string) string

func HashApr1

func HashApr1(password string) (string, error)

func HashApr1WithSalt

func HashApr1WithSalt(password, salt string) (string, error)

Hash hashes the given password, along with the salt. I did not design this algorithm, only re-implement and optimize slightly. This assumes strings are valid UTF-8 encoded strings. The salt must be 8 bytes long. This algorithm is adopted from the Java implementation found here: http://commons.apache.org/proper/commons-codec/apidocs/src-html/org/apache/commons/codec/digest/Md5Crypt.html

func Index

func Index(args []string, index int) string

func Int32

func Int32(str string, base int) *int32

func Int64

func Int64(str string, base int) *int64

func Join

func Join(ms map[string]string, separator, kvSeparator string) string

func Line

func Line(format string, params ...interface{})

func Logs added in v0.5.0

func Logs(format string, args ...interface{})

func Match

func Match(str string, patterns ...string) bool

func Mkdir added in v0.5.0

func Mkdir(dest string) error

func Name

func Name(name, link string) string

func NextIP

func NextIP(ip net.IP) net.IP

func NotExists

func NotExists(path string) bool

func Panic

func Panic(err error, msg string, params ...interface{})

如果不为空,使用msg panic错误,

func ParseIPS

func ParseIPS(nodes []string) []string

func PrevIP

func PrevIP(ip net.IP) net.IP

func Random added in v0.5.0

func Random(n int) string

func RangeIP

func RangeIP(start, end string) []string

func Repeat

func Repeat(str string, size int) []string

func Reverse

func Reverse(strs []string) []string

func Safe

func Safe(fn func()) (err error)
func Search(slice []string, s string) int

func SelectMatch

func SelectMatch(strs []string, patterns ...string) (matched []string)

func SelectNotMatch

func SelectNotMatch(strs []string, patterns ...string) (matched []string)

func Split2

func Split2(str, sep string) (a, b string)

func Split3

func Split3(str, sep string) (a, b, c string)

func Stack

func Stack() string

func Stdout

func Stdout(name string) func(reader io.Reader) error

func Switch

func Switch(assert bool, a, b string) string

func Trdn added in v0.5.0

func Trdn(bs []byte) []byte

tr -d '\n'

func Try

func Try(fun func(), handler ...func(error))

Try handler(err)

func TryFinally

func TryFinally(fun func(), handler func(error), finallyFn func())

Try handler(err) and finally

func UnderscoreName

func UnderscoreName(name string) string

func VersionCompose

func VersionCompose(v1, v2 string) int

版本比较

func Wrap

func Wrap(err error, format string, param ...interface{}) error

Types

type WrapError

type WrapError struct {
	Err     error
	Message string
}

func Error added in v0.5.0

func Error(format string, args ...interface{}) *WrapError

func (WrapError) Error

func (w WrapError) Error() string

Jump to

Keyboard shortcuts

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