mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 11:16:37 +08:00
47 lines
787 B
Go
47 lines
787 B
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// deduplicate removes duplicates from a string slice.
|
|
func deduplicate(s []string) []string {
|
|
if len(s) == 0 {
|
|
return s
|
|
}
|
|
seen := make(map[string]bool, len(s))
|
|
out := make([]string, 0, len(s))
|
|
for _, v := range s {
|
|
if !seen[v] {
|
|
seen[v] = true
|
|
out = append(out, v)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func nonEmptyStrings(values ...string) []string {
|
|
out := make([]string, 0, len(values))
|
|
for _, value := range values {
|
|
value = strings.TrimSpace(value)
|
|
if value != "" {
|
|
out = append(out, value)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func genreIDStrings(ids []int) []string {
|
|
if len(ids) == 0 {
|
|
return nil
|
|
}
|
|
out := make([]string, 0, len(ids))
|
|
for _, id := range ids {
|
|
if id > 0 {
|
|
out = append(out, fmt.Sprint(id))
|
|
}
|
|
}
|
|
return out
|
|
}
|