-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (30 loc) · 693 Bytes
/
main.go
File metadata and controls
37 lines (30 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gocleanups
// Cleanups struct
type Cleanups []func()
// Len returns the number of cleanup functions
func (c Cleanups) Len() int {
return len(c)
}
// Run all Cleanups
func (c Cleanups) Run() {
for _, f := range c {
f()
}
}
// RunAndReset runs all Cleanups and resets funcs to empty slice
func (c *Cleanups) RunAndReset() {
c.Run()
*c = NewCleanups()
}
// Add cleanup funcs to Cleanups
func (c *Cleanups) Add(funcs ...func()) {
*c = append(*c, funcs...)
}
// Export Cleanups as simple func
func (c Cleanups) Export() func() {
return c.Run
}
// NewCleanups constructor
func NewCleanups(funcs ...func()) Cleanups {
return append(make([]func(), 0, len(funcs)), funcs...)
}