Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Log ¶
func Log(err error)
Log 打印错误,配合通过 Wrapper 函数返回的 error 使用。 若未通过 SetLoggerWriter 设置过 writer,则默认打印到 stderr。 输出的格式为:
2020/05/31 16:38:09 an error was caught at runtime: @ [errors.handler]: can not get user by id (utils/errors/wrapper_test.go:30) @ [errors.UserModel.GetUserByID]: query fail (utils/errors/wrapper_test.go:39) @ [origin]: can not connect to db
func SetWrapperOpt ¶
func SetWrapperOpt(opt WrapperOpt)
SetWrapperOpt 根据 opt 改变 Wrapper 函数的行为, 该函数需在调用 Wrapper 函数前执行。
Types ¶
type WrapperOpt ¶
type WrapperOpt struct { // ProjectDir 需设置为编译时所在环境的项目路径, // 该路径会作为前缀抵消堆栈信息里源码文件路径里的该部分, // 如果不设置或者值和编译时项目所在的路径不符, // 则堆栈信息里的源码文件路径则会展示执行编译时文件所在的绝对路径。 // // 若项目文件夹名为 app,在执行编译时项目的路径为 /path/to/app/, // 则需将该值设置为 "/path/to/"。 // // 注意:若使用 Docker 执行多阶段构建,则需将该值为 Docker 容器内项目的绝对路径。 ProjectDir string // ProjectModule 需设置为项目的 Module 名称,即 go.mod 文件第一行指定的项目名称, // 目的同样是为了去除 error 堆栈中函数名称前缀。 // // 若项目 module 名称为 example.com/foo/bar, // 则需将该值设置为 "example.com/foo/bar/"。 ProjectModule string }
WrapperOpt 是 Wrapper 设置项。
Click to show internal directories.
Click to hide internal directories.