Add base code
This commit is contained in:
34
internal/utils/utils.go
Normal file
34
internal/utils/utils.go
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright © 2024 Matteo Schiff <matteo@underdesk.net>
|
||||
|
||||
*/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MeasureTime(start time.Time, name string) {
|
||||
elapsed := time.Since(start)
|
||||
log.Printf("%s took %s", name, elapsed)
|
||||
}
|
||||
|
||||
func mergeElements(slice []string, n int) []string {
|
||||
if n <= 0 {
|
||||
return slice
|
||||
}
|
||||
|
||||
var result []string
|
||||
for i := 0; i < len(slice); i += n {
|
||||
end := i + n
|
||||
if end > len(slice) {
|
||||
end = len(slice)
|
||||
}
|
||||
merged := strings.Join(slice[i:end], ".")
|
||||
result = append(result, merged)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user