github.com/msales/pkg/v3@v3.24.0/clix/utils.go (about) 1 package clix 2 3 import ( 4 "errors" 5 "os" 6 "os/signal" 7 "strings" 8 "syscall" 9 ) 10 11 // SplitTags splits a slice of strings into a slice using 12 // the given separator. 13 func SplitTags(slice []string, sep string) ([]interface{}, error) { 14 res := make([]interface{}, 2*len(slice)) 15 16 for i, str := range slice { 17 parts := strings.SplitN(str, sep, 2) 18 if len(parts) != 2 { 19 return nil, errors.New("invalid tags string") 20 } 21 22 res[2*i] = parts[0] 23 res[2*i+1] = parts[1] 24 } 25 26 return res, nil 27 } 28 29 // WaitForSignals waits for SIGINT or SIGTERM signals. 30 func WaitForSignals() chan os.Signal { 31 sigs := make(chan os.Signal, 1) 32 signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) 33 34 return sigs 35 }