-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal.go
51 lines (46 loc) · 1.45 KB
/
internal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// A Golang JSON document-file based database allowing complex SELECT queries.
package jdocdb
import (
"fmt"
"path/filepath"
"strings"
)
// Returns a lowercase string with the type name for path finding.
func getType(doc interface{}) string {
return strings.ToLower(strings.SplitN(fmt.Sprintf("%T", doc), ".", 2)[1])
}
// Keys returns the keys of the map m. Keys will be in an indeterminate order. Taken
// from https://github.com/golang/exp/blob/master/maps/maps.go which is subject to change
func keys[M ~map[K]V, K comparable, V any](m M) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}
// Prefix and suffix handling:
//
// a) prefix_suffix ...string is [prefix, suffix, ignored, ignored...]string
// in other words, prefix==prefix_suffix[0], suffix==prefix_suffix[1].
// b) If NO PREFIX is specified, the path will be ./person/;
// c) If PREFIX=data, the path will be ./data/person/;
// d) If SUFFIX=people, the path will be ./data/people/.
func buildPath(baseName string, prefix_suffix ...string) string {
prefix, suffix := "", baseName
if len(prefix_suffix) > 0 {
prefix = prefix_suffix[0]
}
if len(prefix_suffix) > 1 {
suffix = prefix_suffix[1]
}
buildPath := filepath.Clean(filepath.Join(prefix, suffix)) + "/"
return buildPath
}
// A simple sum, waiting to find a proper mathematical statistics package.
func sum[T int](array []T) T {
var result T = 0
for _, v := range array {
result += v
}
return result
}