bzcode

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IfErrPanic

func IfErrPanic(err error)

func Ternary

func Ternary[T any](b bool, v1 T, v2 T) T

Ternary 可以实现简单的条件判断功能。go原生不支持三元运算符,本函数可以提供类似的使用方式 Ternary[T any](b bool, v1 T, v2 T) T @param b bool 条件:true时返回v1;false时返回v2 @param v1 T 值1,条件为true时作为返回值 @param v2 T 值2,条件为false时作为返回值

func TryCatch

func TryCatch(tryFn func(), catchFn func(err Exception))

TryCatch 捕捉panic错误,防止服务退出,并提供error错误。go原生不支持try-catch语法,对于习惯try-catch的开发者来说很难受,虽然这是一种不好的习惯 TryCatch(tryFn func(), catchFn func(err bzcode.Exception)) @param tryFn func() 代码容器 @param catchFn func(err bzcode.Exception) 代码容器中发生panic错误后返回的error message

Types

type Exception

type Exception struct {
	// contains filtered or unexported fields
}

func (*Exception) Message

func (e *Exception) Message() string

func (*Exception) Stack

func (e *Exception) Stack() string

Jump to

Keyboard shortcuts

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