refractor: add initial go internall pkg module.
This commit is contained in:
parent
ef8029e086
commit
049b939349
4 changed files with 289 additions and 0 deletions
40
pkg/util/tools.go
Normal file
40
pkg/util/tools.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// apparmor.d - Full set of apparmor profiles
|
||||
// Copyright (C) 2023 Alexandre Pujol <alexandre@pujol.io>
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var isHexa = regexp.MustCompile("^[0-9A-Fa-f]+$")
|
||||
|
||||
// DecodeHex decode a string if it is hexa.
|
||||
func DecodeHex(str string) string {
|
||||
if isHexa.MatchString(str) {
|
||||
bs, _ := hex.DecodeString(str)
|
||||
return string(bs)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
// RemoveDuplicate filter out all duplicates from a slice. Also filter out empty string
|
||||
func RemoveDuplicate[T comparable](inlist []T) []T {
|
||||
var empty T
|
||||
list := []T{}
|
||||
keys := map[T]bool{}
|
||||
keys[empty] = true
|
||||
for _, item := range inlist {
|
||||
if _, ok := keys[item]; !ok {
|
||||
keys[item] = true
|
||||
list = append(list, item)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue