safe

package
v1.89.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package safe 提供 goroutine panic 治理工具: 业务/回调在独立 goroutine 中 panic 时,默认行为是崩溃整个进程; safe.Go 捕获 panic 并记录日志与堆栈,保证服务继续运行。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(name string, fn func())

Go 启动带 panic 恢复的 goroutine:fn 内部 panic 会被捕获, 记录组件名、错误与堆栈后继续运行(不崩溃进程)。 用法:

safe.Go("redqueue consume", func() { ... })

func Recover

func Recover(name string)

Recover 供 defer 使用:捕获当前 goroutine 的 panic 并记录日志。

defer safe.Recover("my goroutine")

Types

This section is empty.

Jump to

Keyboard shortcuts

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