Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
41
pkg/utils/map_helper.go
Normal file
41
pkg/utils/map_helper.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package utils
|
||||
|
||||
type MapHelper struct {
|
||||
}
|
||||
|
||||
func (h *MapHelper) GetString(m map[string]interface{}, key string, defaultVal string) string {
|
||||
val, ok := m[key]
|
||||
if !ok {
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
result, ok := val.(string)
|
||||
if !ok {
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (h *MapHelper) GetData(m map[string]interface{}, key string) []byte {
|
||||
val, ok := m[key]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO maybe there is a better way to serialize and deserialize JSON RPC binary data
|
||||
// Go by default does not convert []uint JSON into []byte. Thus the code below
|
||||
vals, ok := val.([]interface{})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
var x int64
|
||||
result := make([]byte, len(vals))
|
||||
for i, value := range vals {
|
||||
x = int64(value.(float64))
|
||||
result[i] = byte(x)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user