Version: v0.0.8 Latest Latest

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

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




View Source
const (
	IpTypeUnknown = iota
View Source
const (
	BYTE ByteSize = 1
	KB            = 1024 * BYTE
	MB            = 1024 * KB
	GB            = 1024 * MB
	TB            = 1024 * GB

Common units for calculating size

View Source
const Separator = '='


View Source
var (
	ErrPathUnauthorized = errors.New("access path unauthorized")
View Source
var IsRelByBasedir = true
View Source
var (
	TypeMustBeStruct = errors.New("type must be struct")


func BaseDir

func BaseDir() string

func DumpHex added in v0.0.2

func DumpHex(bs []byte, wordsPerLine ...int) (s string)

func ExecCommandAndFind

func ExecCommandAndFind(cmd Command, pattern string) (exitStatus int, results []string, err error)

func Exists

func Exists(path string) bool


func FilePathJoinSafely

func FilePathJoinSafely(base string, children ...string) (string, error)

func FindByRegexp

func FindByRegexp(in, pattern string) (match []string)

func GenKeyForMap

func GenKeyForMap(values ...string) string

func GetBoolFromArgs

func GetBoolFromArgs(key string, defaultValueOrNone ...bool) (value bool)

func GetFileInfo

func GetFileInfo(path string) (abs, dir, pureFilename, suffix string)

func GetFromArgs

func GetFromArgs(key string, defaultValueOrNone ...string) (value string)

func GetFuncInfo

func GetFuncInfo(skip int) (file string, line int, funcName string, ok bool)

func GetIPs

func GetIPs() (map[string][]*Address, error)

func GetIntFromArgs

func GetIntFromArgs(key string, defaultValueOrNone ...int64) (value int64)

func GetInterface

func GetInterface(flags ...net.Flags) ([]net.Interface, error)

func GetInterfaceName

func GetInterfaceName(flags ...net.Flags) (names []string, e error)

func GetLinuxStylePath added in v0.0.2

func GetLinuxStylePath(path string) (linuxPath string)

func GetUintFromArgs

func GetUintFromArgs(key string, defaultValueOrNone ...uint64) (value uint64)

func HideString

func HideString(s string, beginPosShown int, endPosShownOrNone ...int) string

func IsByteVisible added in v0.0.2

func IsByteVisible(c byte) bool

func IsDir

func IsDir(path string) bool


func IsFile

func IsFile(path string) bool


func JsonDump

func JsonDump(v interface{}, indent int) string

func JsonDumpE added in v0.0.8

func JsonDumpE(v interface{}, indent int) (result string, err error)

func MapToStruct added in v0.0.7

func MapToStruct(inputMap map[string]interface{}, outStructPtr interface{}) error

func MapToStructByJson added in v0.0.8

func MapToStructByJson(inputMap map[string]interface{}, outStructPtr interface{}) error

func MergeMap added in v0.0.3

func MergeMap(dest, addition map[string]interface{}, mode MergeMode)

func MergeStruct added in v0.0.3

func MergeStruct(out, in interface{}, mode MergeMode) (result interface{}, err error)

func Panic

func Panic(err error, reason ...string)

func PickArgs

func PickArgs() map[string]string

Use for pick up arguments into map, either `go run` or `go test`.

func PrintStack

func PrintStack()

func PythonLikePos

func PythonLikePos(length, beg int, endOrNone ...int) (begin, end int)

func PythonLikeSlice

func PythonLikeSlice(s string, beg int, endOrNone ...int) string

func RelativeDirByBase

func RelativeDirByBase(targpath string) string

func ResetHiddenReplacer

func ResetHiddenReplacer(r string)

func StructToMap added in v0.0.3

func StructToMap(o interface{}) map[string]interface{}

func StructToString added in v0.0.3

func StructToString(s interface{}, showZero ...bool) (result string)

func VectorToMap

func VectorToMap(vector interface{}, keys ...string) (mapResult *map[string]interface{})


type Address

type Address struct {

func GetIPByInterface

func GetIPByInterface(netInterfaces ...*net.Interface) ([]*Address, error)

func GetIPByInterfaceName

func GetIPByInterfaceName(interfaceNames ...string) ([]*Address, error)

func NewAddress

func NewAddress(CIDR string) (*Address, error)

func (Address) ConvertIPNet

func (a Address) ConvertIPNet() (string, error)

func (Address) GetIpType

func (a Address) GetIpType() IpType

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

func (Address) String

func (a Address) String() (CIDR string)

func (Address) ToMultiaddr

func (a Address) ToMultiaddr(returnErr ...*error) multiaddr.Multiaddr

func (*Address) ToTcpAddr

func (a *Address) ToTcpAddr(portOrNone ...int) (*net.TCPAddr, error)

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

type ByteSize added in v0.0.7

type ByteSize uint64

func (ByteSize) Add added in v0.0.7

func (s ByteSize) Add(arg ByteSize) ByteSize

func (ByteSize) Del added in v0.0.7

func (s ByteSize) Del(arg ByteSize) ByteSize

func (ByteSize) Div added in v0.0.7

func (s ByteSize) Div(arg ByteSize) ByteSize

func (ByteSize) GB added in v0.0.7

func (s ByteSize) GB() ByteSize

func (ByteSize) KB added in v0.0.7

func (s ByteSize) KB() ByteSize

func (ByteSize) MB added in v0.0.7

func (s ByteSize) MB() ByteSize

func (ByteSize) Mul added in v0.0.7

func (s ByteSize) Mul(arg ByteSize) ByteSize

func (ByteSize) TB added in v0.0.7

func (s ByteSize) TB() ByteSize

type CIDRAddress

type CIDRAddress string


func (CIDRAddress) ToAddress

func (s CIDRAddress) ToAddress() (*Address, error)

type Command

type Command struct {
	Cmd  string
	Args []string

func NewCommand

func NewCommand(cmd string, arg ...string) *Command

type ExecResult

type ExecResult struct {
	Stdout     string
	Stderr     string
	ExitStatus int
	Error      error

func ExecCommand

func ExecCommand(name string, arg ...string) *ExecResult

func ExecCommandContext

func ExecCommandContext(ctx context.Context,
	name string, arg ...string) *ExecResult

func NewExecResult

func NewExecResult(stdout, stderr string, execErr error) *ExecResult

type IpType

type IpType uint8

func GetIpType

func GetIpType(ip net.IP) IpType

func (IpType) String

func (t IpType) String() string

type MergeMode added in v0.0.5

type MergeMode int
const (
	// Overwrite the non-empty fields in A (addition) over the corresponding fields in D (dest).
	// For short: A(non-empty fields) ----> D
	OverwriteWithNonEmpty MergeMode = iota
	// Overwrite all fields owned by A (addition).
	// For short: A(all fields) ----> D
	// Fill in the blank field of D (dest) with corresponding fields in A (addition).
	// In this way, fields that have non-empty values will not be affected.
	// For short: A(non-empty fields that is empty in D) ----> D

Merge A -> D

type MyError

type MyError struct {
	Error  error
	Reason string

func DealWithPanic

func DealWithPanic(panicVal interface{}) *MyError

func NewError

func NewError(err error, reason ...string) *MyError

type Version

type Version struct {
	Major    uint16 // 主版本号
	Minor    uint16 // 次版本号
	Patch    uint16 // 修订版本号
	Addition string // 附加信息

func NewVersion

func NewVersion(ver string) *Version

@param {string} ver 字符串格式的版本号,兼容格式 [v]1.2.3{foo}

func (*Version) Equal

func (v *Version) Equal(w *Version) bool

func (*Version) FromDB

func (v *Version) FromDB(data []byte) error

func (*Version) GreaterThan

func (v *Version) GreaterThan(w *Version) bool

func (*Version) IsZero

func (v *Version) IsZero() bool

func (Version) MarshalJSON

func (v Version) MarshalJSON() ([]byte, error)

func (*Version) Set

func (v *Version) Set(ver string) error

func (*Version) String

func (v *Version) String() string

func (*Version) ToDB

func (v *Version) ToDB() ([]byte, error)

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

func (*Version) UnmarshalYAML

func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error


Path Synopsis

Jump to

Keyboard shortcuts

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