cleaner

package
v0.0.0-...-5e2b60c Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

cleaner包,用于程序退出时,执行清理操作

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCleaner

func AddCleaner(key string, ec ExitCleaner) error

添加清理器到默认清理列表

func Exit

func Exit(n int)

默认清理列表退出函数

Types

type CleanList

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

定义清理列表

func NewCleanList

func NewCleanList() *CleanList

创建一个新的清理列表

func (*CleanList) Add

func (p *CleanList) Add(key string, ec ExitCleaner) error

将清理加入列表

func (*CleanList) Exit

func (p *CleanList) Exit(n int, f func(key interface{}, value interface{}) bool)

清理列表的退出方法,调用传入的回调函数 清理器的签名方法将在回调函数中执行

type Cleaner

type Cleaner struct {
	F func() // 回调函数
}

定义清理器

func (*Cleaner) ExitClean

func (p *Cleaner) ExitClean() error

实现清理器接口 在此方法中调用回调函数

func (*Cleaner) HandleFunc

func (p *Cleaner) HandleFunc(f func())

添加回调函数

type ExitCleaner

type ExitCleaner interface {
	ExitClean() error // 清理方法签名,清理器实际执行的逻辑在该方法中实现
}

定义清理器接口

Jump to

Keyboard shortcuts

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