github.com/fawick/restic@v0.1.1-0.20171126184616-c02923fbfc79/internal/debug/hooks.go (about)

     1  // +build !release
     2  
     3  package debug
     4  
     5  var (
     6  	hooks map[string]func(interface{})
     7  )
     8  
     9  func init() {
    10  	hooks = make(map[string]func(interface{}))
    11  }
    12  
    13  func Hook(name string, f func(interface{})) {
    14  	hooks[name] = f
    15  }
    16  
    17  func RunHook(name string, context interface{}) {
    18  	f, ok := hooks[name]
    19  	if !ok {
    20  		return
    21  	}
    22  
    23  	f(context)
    24  }
    25  
    26  func RemoveHook(name string) {
    27  	delete(hooks, name)
    28  }