/
dbtasks_get.go
87 lines (73 loc) · 1.82 KB
/
dbtasks_get.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package goshare
import (
golhashmap "github.com/abhishekkr/gol/golhashmap"
golkeyvalNS "github.com/abhishekkr/gol/golkeyvalNS"
golkeyvalTSDS "github.com/abhishekkr/gol/golkeyvalTSDS"
)
/*
ReadKey gets value of given key.
*/
func ReadKey(key string) golhashmap.HashMap {
var hashmap golhashmap.HashMap
hashmap = make(golhashmap.HashMap)
val := db.GetVal(key)
if val == "" {
return hashmap
}
hashmap[key] = val
return hashmap
}
/*
ReadKeyNS gets value for all descendents of given key's namespace.
*/
func ReadKeyNS(key string) golhashmap.HashMap {
return golkeyvalNS.ReadNSRecursive(key, db)
}
/*
ReadKeyTSDS gets value for the asked time-frame key, aah same NS.
*/
func ReadKeyTSDS(key string) golhashmap.HashMap {
return golkeyvalTSDS.ReadTSDS(key, db)
}
/*
ReadFuncByKeyType calls a read task on task-type.
*/
func ReadFuncByKeyType(keyType string) FunkAxnParamKeyReturnMap {
switch keyType {
case "tsds":
return ReadKeyTSDS
case "ns":
return ReadKeyNS
default:
return ReadKey
}
}
/*
ReadFromPacket calls ReadFuncByKeyType for multi-keys based on provided packet.
*/
func ReadFromPacket(packet Packet) string {
var response string
var hashmap golhashmap.HashMap
hashmap = make(golhashmap.HashMap)
axnFunk := ReadFuncByKeyType(packet.KeyType)
for _, _key := range packet.KeyList {
hashmap = axnFunk(_key)
if len(hashmap) == 0 {
continue
}
response += responseByValType(packet.ValType, hashmap)
}
return response
}
/* transform response by ValType, if none default:csv */
func responseByValType(valType string, responseMap golhashmap.HashMap) string {
var response string
switch valType {
case "csv", "json":
hashmapEngine := golhashmap.GetHashMapEngine(valType)
response = hashmapEngine.FromHashMap(responseMap)
default:
response = golhashmap.HashMapToCSV(responseMap)
}
return response
}