mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
refactor: include generics based utility lib and refactor some parts accordingly [ci-skip]
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package utils
|
||||
|
||||
func GetMapValues(m map[string]interface{}) []interface{} {
|
||||
values := make([]interface{}, 0, len(m))
|
||||
for _, v := range m {
|
||||
values = append(values, v)
|
||||
}
|
||||
return values
|
||||
}
|
@@ -5,6 +5,12 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// TODO: replace these functions by github.com/duke-git/lancet/v2/datetime
|
||||
// needs additional thoughts, though, as for "EndOfX" functions, we currently return the discrete next day,
|
||||
// while the above lib returns the very last nanosecond of the current day, i.e.
|
||||
// 2022-02-15 23:59:59.999 +0800 CST vs. 2022-02-16 00:00:00.000 +0800 CST
|
||||
// -> need to revisit comparison logic, etc.
|
||||
|
||||
func StartOfDay(date time.Time) time.Time {
|
||||
return FloorDate(date)
|
||||
}
|
||||
|
17
utils/set.go
17
utils/set.go
@@ -1,17 +0,0 @@
|
||||
package utils
|
||||
|
||||
func StringsToSet(slice []string) map[string]bool {
|
||||
set := make(map[string]bool, len(slice))
|
||||
for _, e := range slice {
|
||||
set[e] = true
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func SetToStrings(set map[string]bool) []string {
|
||||
slice := make([]string, 0, len(set))
|
||||
for k := range set {
|
||||
slice = append(slice, k)
|
||||
}
|
||||
return slice
|
||||
}
|
@@ -8,12 +8,3 @@ import (
|
||||
func Capitalize(s string) string {
|
||||
return fmt.Sprintf("%s%s", strings.ToUpper(s[:1]), s[1:])
|
||||
}
|
||||
|
||||
func FindString(needle string, haystack []string, defaultVal string) string {
|
||||
for _, s := range haystack {
|
||||
if s == needle {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
Reference in New Issue
Block a user