- add callback sign check.
This commit is contained in:
38
utils/errorwithcode.go
Normal file
38
utils/errorwithcode.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ErrorWithCode struct {
|
||||
str string
|
||||
code string
|
||||
intCode int
|
||||
}
|
||||
|
||||
func NewErrorCode(err, code string) *ErrorWithCode {
|
||||
return &ErrorWithCode{
|
||||
str: err,
|
||||
code: code,
|
||||
intCode: Str2Int(code),
|
||||
}
|
||||
}
|
||||
|
||||
func NewErrorIntCode(err string, code int) *ErrorWithCode {
|
||||
return &ErrorWithCode{
|
||||
str: err,
|
||||
code: Int2Str(code),
|
||||
intCode: code,
|
||||
}
|
||||
}
|
||||
func (e *ErrorWithCode) Error() string {
|
||||
return fmt.Sprintf("%s, code:%s", e.str, e.code)
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) Code() string {
|
||||
return e.code
|
||||
}
|
||||
|
||||
func (e *ErrorWithCode) IntCode() int {
|
||||
return e.intCode
|
||||
}
|
||||
@@ -173,3 +173,15 @@ func MustInterface2Int64(data interface{}) int64 {
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interface{}) (retVal map[string]interface{}) {
|
||||
retVal = make(map[string]interface{})
|
||||
allMaps := append(otherMaps, firstMap)
|
||||
for _, oneMap := range allMaps {
|
||||
for k, v := range oneMap {
|
||||
retVal[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -29,3 +30,47 @@ func TestDictKeysMan(t *testing.T) {
|
||||
t.Error("Params keysToKeep keep wrong key!")
|
||||
}
|
||||
}
|
||||
|
||||
type TestModel struct {
|
||||
IntData int
|
||||
Int64Data int64
|
||||
FloatData float64
|
||||
StrData string
|
||||
}
|
||||
|
||||
type TestModel2 struct {
|
||||
IntData int
|
||||
Int64Data int64
|
||||
FloatData float64
|
||||
AddData string
|
||||
}
|
||||
|
||||
func unmarshStr(t *testing.T, jsonStr string, obj interface{}) {
|
||||
|
||||
err := UnmarshalUseNumber([]byte(jsonStr), obj)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
fmt.Println(obj)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJson(t *testing.T) {
|
||||
jsonStr := `
|
||||
{
|
||||
"IntData": 1,
|
||||
"Int64Data": 1234567890123456,
|
||||
"FloatData": 1234.5678,
|
||||
"StrData": "str"
|
||||
}
|
||||
`
|
||||
obj1 := make(map[string]interface{})
|
||||
var obj2 interface{}
|
||||
var obj3 TestModel
|
||||
var obj4 TestModel2
|
||||
|
||||
unmarshStr(t, jsonStr, &obj1)
|
||||
unmarshStr(t, jsonStr, &obj2)
|
||||
unmarshStr(t, jsonStr, &obj3)
|
||||
unmarshStr(t, jsonStr, &obj4)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user