You've already forked openaccounting-server
mirror of
https://github.com/openaccounting/oa-server.git
synced 2025-12-09 09:00:42 +13:00
mailgun dep
This commit is contained in:
63
vendor/github.com/stretchr/objx/map.go
generated
vendored
63
vendor/github.com/stretchr/objx/map.go
generated
vendored
@@ -47,9 +47,8 @@ func New(data interface{}) Map {
|
||||
//
|
||||
// The arguments follow a key, value pattern.
|
||||
//
|
||||
// Panics
|
||||
//
|
||||
// Panics if any key argument is non-string or if there are an odd number of arguments.
|
||||
// Returns nil if any key argument is non-string or if there are an odd number of arguments.
|
||||
//
|
||||
// Example
|
||||
//
|
||||
@@ -58,14 +57,13 @@ func New(data interface{}) Map {
|
||||
// m := objx.MSI("name", "Mat", "age", 29, "subobj", objx.MSI("active", true))
|
||||
//
|
||||
// // creates an Map equivalent to
|
||||
// m := objx.New(map[string]interface{}{"name": "Mat", "age": 29, "subobj": map[string]interface{}{"active": true}})
|
||||
// m := objx.Map{"name": "Mat", "age": 29, "subobj": objx.Map{"active": true}}
|
||||
func MSI(keyAndValuePairs ...interface{}) Map {
|
||||
newMap := make(map[string]interface{})
|
||||
newMap := Map{}
|
||||
keyAndValuePairsLen := len(keyAndValuePairs)
|
||||
if keyAndValuePairsLen%2 != 0 {
|
||||
panic("objx: MSI must have an even number of arguments following the 'key, value' pattern.")
|
||||
return nil
|
||||
}
|
||||
|
||||
for i := 0; i < keyAndValuePairsLen; i = i + 2 {
|
||||
key := keyAndValuePairs[i]
|
||||
value := keyAndValuePairs[i+1]
|
||||
@@ -73,11 +71,11 @@ func MSI(keyAndValuePairs ...interface{}) Map {
|
||||
// make sure the key is a string
|
||||
keyString, keyStringOK := key.(string)
|
||||
if !keyStringOK {
|
||||
panic("objx: MSI must follow 'string, interface{}' pattern. " + keyString + " is not a valid key.")
|
||||
return nil
|
||||
}
|
||||
newMap[keyString] = value
|
||||
}
|
||||
return New(newMap)
|
||||
return newMap
|
||||
}
|
||||
|
||||
// ****** Conversion Constructors
|
||||
@@ -99,12 +97,50 @@ func MustFromJSON(jsonString string) Map {
|
||||
//
|
||||
// Returns an error if the JSON is invalid.
|
||||
func FromJSON(jsonString string) (Map, error) {
|
||||
var data interface{}
|
||||
err := json.Unmarshal([]byte(jsonString), &data)
|
||||
var m Map
|
||||
err := json.Unmarshal([]byte(jsonString), &m)
|
||||
if err != nil {
|
||||
return Nil, err
|
||||
}
|
||||
return New(data), nil
|
||||
m.tryConvertFloat64()
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Map) tryConvertFloat64() {
|
||||
for k, v := range m {
|
||||
switch v.(type) {
|
||||
case float64:
|
||||
f := v.(float64)
|
||||
if float64(int(f)) == f {
|
||||
m[k] = int(f)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
t := New(v)
|
||||
t.tryConvertFloat64()
|
||||
m[k] = t
|
||||
case []interface{}:
|
||||
m[k] = tryConvertFloat64InSlice(v.([]interface{}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func tryConvertFloat64InSlice(s []interface{}) []interface{} {
|
||||
for k, v := range s {
|
||||
switch v.(type) {
|
||||
case float64:
|
||||
f := v.(float64)
|
||||
if float64(int(f)) == f {
|
||||
s[k] = int(f)
|
||||
}
|
||||
case map[string]interface{}:
|
||||
t := New(v)
|
||||
t.tryConvertFloat64()
|
||||
s[k] = t
|
||||
case []interface{}:
|
||||
s[k] = tryConvertFloat64InSlice(v.([]interface{}))
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// FromBase64 creates a new Obj containing the data specified
|
||||
@@ -170,12 +206,11 @@ func FromURLQuery(query string) (Map, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := make(map[string]interface{})
|
||||
m := Map{}
|
||||
for k, vals := range vals {
|
||||
m[k] = vals[0]
|
||||
}
|
||||
return New(m), nil
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// MustFromURLQuery generates a new Obj by parsing the specified
|
||||
|
||||
Reference in New Issue
Block a user