mirror of
https://github.com/maride/pancap.git
synced 2026-04-13 10:35:45 +00:00
Move common code into new package, 'common'
This commit is contained in:
30
common/common.go
Normal file
30
common/common.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package common
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Appends the appendee to the array if it does not contain appendee yet
|
||||
func AppendIfUnique(appendee string, array []string) []string {
|
||||
// Iterate over all elements and check values
|
||||
for _, elem := range array {
|
||||
if elem == appendee {
|
||||
// ... found. Stop here
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
// None found, append
|
||||
return append(array, appendee)
|
||||
}
|
||||
|
||||
// Prints each element, along with a small ASCII tree
|
||||
func PrintTree(strarr []string) {
|
||||
// iterate over each element
|
||||
for iter, elem := range strarr {
|
||||
// check if we got the last element
|
||||
if iter < len(strarr) - 1 {
|
||||
fmt.Printf("|- %s\n", elem)
|
||||
} else {
|
||||
fmt.Printf("'- %s\n\n", elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user