-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
35 lines (29 loc) · 779 Bytes
/
common.go
File metadata and controls
35 lines (29 loc) · 779 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
package utilpkg
import (
"log"
"os"
"os/signal"
"syscall"
)
// Keep a Go process alive by listening to process interrupt calls.
func KeepAlive() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}
// Log an error with given context and the error itself
func Report(context string, err error) {
log.Printf("%s.\n%s", context, err.Error())
}
// RemoveFromSlice takes <removeString string> <list []string>
// RemoveFromSlice removes a specific string form a slice.
// Returns []string
func RemoveFromSlice(removeString string, list []string) []string {
indexItem := 0
for index, item := range list {
if item == removeString {
indexItem = index
}
}
return append(list[:indexItem], list[indexItem+1:]...)
}