stdutil

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package stdutil provide some standard util functions for go.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefStackLen = 10000
	MaxStackLen = 100000
)

Functions

func CutFuncName added in v0.5.0

func CutFuncName(fullFcName string) (pkgPath, shortFnName string)

CutFuncName get pkg path and short func name

func FuncName added in v0.4.2

func FuncName(fn interface{}) string

FuncName get full func name, contains pkg path. eg:

// OUTPUT: github.com/gookit/goutil/stdutil.PanicIf
stdutil.FuncName(stdutil.PkgName)

func GetCallStacks added in v0.4.2

func GetCallStacks(all bool) []byte

GetCallStacks stacks is a wrapper for runtime. If all is true, Stack that attempts to recover the data for all goroutines.

from glog package

func GetCallerInfo added in v0.5.0

func GetCallerInfo(skip int) string

GetCallerInfo get caller func name and with base filename and line.

returns:

github.com/gookit/goutil/stdutil_test.someFunc2(),stack_test.go:26

func GetCallersInfo added in v0.4.2

func GetCallersInfo(skip, max int) []string

GetCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading. NOTICE: max should > skip

func Go added in v0.4.2

func Go(f func() error) error

Go is a basic promise implementation: it wraps calls a function in a goroutine and returns a channel which will later return the function's return value.

func MustString

func MustString(v interface{}) string

MustString convert value(basic type) to string, will panic on convert a complex type.

func PanicIf

func PanicIf(err error)

PanicIf if error is not empty

func PanicIfErr

func PanicIfErr(err error)

PanicIfErr if error is not empty

func Panicf

func Panicf(format string, v ...interface{})

Panicf format panic message use fmt.Sprintf

func PkgName added in v0.4.2

func PkgName(fullFcName string) string

PkgName get current package name

Usage:

fullFcName := stdutil.FuncName(fn)
pgkName := stdutil.PkgName(fullFcName)

func SimpleCallersInfo added in v0.5.0

func SimpleCallersInfo(skip, num int) []string

SimpleCallersInfo returns an array of strings containing the func name, file and line number of each stack frame leading.

func ToString

func ToString(v interface{}) string

ToString always convert value to string

func TryString

func TryString(v interface{}) (string, error)

TryString try to convert a value to string

func WaitCloseSignals added in v0.4.2

func WaitCloseSignals(closer io.Closer) error

WaitCloseSignals for some huang program.

Types

type FullFcName added in v0.5.0

type FullFcName struct {
	// FullName eg: github.com/gookit/goutil/stdutil.PanicIf
	FullName string
	// contains filtered or unexported fields
}

FullFcName struct.

func (*FullFcName) FuncName added in v0.5.0

func (ffn *FullFcName) FuncName() string

FuncName get short func name. eg: PanicIf

func (*FullFcName) Parse added in v0.5.0

func (ffn *FullFcName) Parse()

Parse the full func name.

func (*FullFcName) PkgName added in v0.5.0

func (ffn *FullFcName) PkgName() string

PkgName string get. eg: stdutil

func (*FullFcName) PkgPath added in v0.5.0

func (ffn *FullFcName) PkgPath() string

PkgPath string get. eg: github.com/gookit/goutil/stdutil

func (*FullFcName) String added in v0.5.0

func (ffn *FullFcName) String() string

String get full func name string.

type Value added in v0.5.0

type Value struct {
	// V value
	V interface{}
}

Value data store

func (Value) Bool added in v0.5.0

func (v Value) Bool() bool

Bool value

func (Value) Float64 added in v0.5.0

func (v Value) Float64() float64

Float64 value

func (Value) Int added in v0.5.0

func (v Value) Int() int

Int value

func (Value) Int64 added in v0.5.0

func (v Value) Int64() int64

Int64 value

func (Value) IsEmpty added in v0.5.0

func (v Value) IsEmpty() bool

IsEmpty value

func (*Value) Reset added in v0.5.0

func (v *Value) Reset()

Reset value

func (Value) String added in v0.5.0

func (v Value) String() string

String value

func (Value) Strings added in v0.5.0

func (v Value) Strings() (ss []string)

Strings value

func (Value) Val added in v0.5.0

func (v Value) Val() interface{}

Val get

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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