sys

package
v0.0.0-...-110d06e Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultErrFormat = func(c *CallerInfo, format string, a ...interface{}) string {
	return fmt.Sprintf("%s %s:%d %s ", emoji.Error, c.Name, c.Line, fmt.Sprintf(format, a...))
}
View Source
var (
	// ErrParamsNotAdapted  params length invalid
	ErrParamsNotAdapted = errors.New("The number of params is not adapted.")
)
View Source
var Organize = ""

Organize 项目组织名称,如github.com/hollson/gdk中的hollson

Functions

func Errorf

func Errorf(format string, a ...interface{}) error
Example
package main

import (
	"fmt"

	"github.com/hollson/gdk/sys"
)

func main() {
	sys.Organize = "gdk"
	fmt.Println(sys.Errorf("===%s===", "sorry"))

}
Output:

❌ gdk/sys_test.ExampleErrorf:25 ===[sorry]===

func OS

func OS()

func T3

func T3(b bool, x, y any) any

T3 三目运算(ternary)

func WrapError

func WrapError(err error, wrapMsg string) error

*

  • 用特定信息包装一个 error,使其包含代码堆栈信息
  • 如果 err 为空则返回空

func WrapErrorf

func WrapErrorf(err error, wrapMsgFmt string, a ...interface{}) error

*

  • 用特定信息包装一个 error,使其包含代码堆栈信息
  • 如果 err 为空则返回空

Types

type CallerInfo

type CallerInfo struct {
	PC   uintptr // 调用者函数指针
	Path string  // 调用者文件路径
	Name string  // 调用者函数名
	Line int     // 调用者行号
}

func Caller

func Caller(skips ...int) (*CallerInfo, error)

Caller 获取调用者信息

func CallerMust

func CallerMust() *CallerInfo

CallerMust 参考sys.Caller

Example
package main

import (
	"fmt"

	"github.com/hollson/gdk"
	"github.com/hollson/gdk/sys"
)

func main() {
	c := sys.CallerMust()
	fmt.Printf("%s\n", gdk.JsonPretty(c))
	fmt.Printf("%v\n", c.Path)

	sys.Organize = "gdk"
	c = sys.CallerMust()
	fmt.Printf("%s", gdk.JsonPretty(c))

	// Output
	// {
	//	"PC": 17790296,
	//	"Path": "/Users/xxx/github/gdk/sys/fn_test.go",
	//	"Name": "github.com/hollson/gdk/sys_test.ExampleCallerMust",
	//	"Line": 19
	// }
}
Output:

type Funcs

type Funcs map[string]reflect.Value

Funcs bundle of functions

func NewFuncs

func NewFuncs() Funcs

NewFuncs function maps

func (Funcs) Bind

func (f Funcs) Bind(name string, fn interface{}) (err error)

Bind the function with the given function name

func (Funcs) Call

func (f Funcs) Call(name string, params ...interface{}) (result []reflect.Value, err error)

Call the function with the given name and params

type Redirect

type Redirect int

Redirect 终端重定向

const (
	Stdin    Redirect = iota // 0:标准输入
	Stdout                   // 1:标准输出
	Stderr                   // 2:标准错误
	Pipeline                 // 3:管道输出(文件流等)
)

Jump to

Keyboard shortcuts

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