- Interface2DirectIntWithDefault added.
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package jdapi
|
package jdapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -49,3 +52,27 @@ func TestQueryStockCenter(t *testing.T) {
|
|||||||
baseapi.SugarLogger.Debug(v)
|
baseapi.SugarLogger.Debug(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TTest struct {
|
||||||
|
A int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TTest) Foo(param1 int, param2 string) string {
|
||||||
|
fmt.Println(param1, param2)
|
||||||
|
return utils.Int2Str(param1) + "|" + param2
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIt(t *testing.T) {
|
||||||
|
var param1, param2 interface{}
|
||||||
|
param1 = 1
|
||||||
|
param2 = "bbb"
|
||||||
|
var tt interface{}
|
||||||
|
tt = &TTest{}
|
||||||
|
ttValue := reflect.ValueOf(tt)
|
||||||
|
funcFoo := ttValue.MethodByName("Foo")
|
||||||
|
params := []reflect.Value{
|
||||||
|
reflect.ValueOf(param1),
|
||||||
|
reflect.ValueOf(param2),
|
||||||
|
}
|
||||||
|
fmt.Println(funcFoo.Call(params)[0])
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ func Interface2Int64WithDefault(data interface{}, defValue int64) int64 {
|
|||||||
return MustInterface2Int64(data)
|
return MustInterface2Int64(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Interface2DirectIntWithDefault(data interface{}, defValue int) int {
|
||||||
|
if data == nil {
|
||||||
|
return defValue
|
||||||
|
}
|
||||||
|
return data.(int)
|
||||||
|
}
|
||||||
|
|
||||||
func MustInterface2Float64(data interface{}) float64 {
|
func MustInterface2Float64(data interface{}) float64 {
|
||||||
dataNumber, ok := data.(json.Number)
|
dataNumber, ok := data.(json.Number)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user