Compare commits
No commits in common. "master" and "revert-c06889aa" have entirely different histories.
master
...
revert-c06
|
@ -24,6 +24,11 @@
|
||||||
# go-tests = true
|
# go-tests = true
|
||||||
# unused-packages = true
|
# unused-packages = true
|
||||||
|
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/corpix/reflect"
|
||||||
|
|
||||||
[prune]
|
[prune]
|
||||||
go-tests = true
|
go-tests = true
|
||||||
unused-packages = true
|
unused-packages = true
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
our "git.loafle.net/overflow/util-go/reflect"
|
cr "github.com/corpix/reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetValueWithJSONStringArray set the value of json string array
|
// SetValueWithJSONStringArray set the value of json string array
|
||||||
|
@ -41,7 +41,7 @@ func SetValueWithJSONStringArray(values []string, targets []interface{}) error {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
return fmt.Errorf("Type of target[%d] cannot be double ptr, value=%s", indexI, value)
|
return fmt.Errorf("Type of target[%d] cannot be double ptr, value=%s", indexI, value)
|
||||||
default:
|
default:
|
||||||
cv, err := our.ConvertToType(value, reflect.TypeOf(target).Elem())
|
cv, err := cr.ConvertToType(value, reflect.TypeOf(target).Elem())
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return fmt.Errorf("Type conversion of value[%s] has been failed to %s[%d]", value, reflect.TypeOf(target).Elem().Kind(), indexI)
|
return fmt.Errorf("Type conversion of value[%s] has been failed to %s[%d]", value, reflect.TypeOf(target).Elem().Kind(), indexI)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConvertToType(v interface{}, t Type) (interface{}, error) {
|
func ConvertToType(v interface{}, t reflect.Type) (interface{}, error) {
|
||||||
var (
|
var (
|
||||||
tt = reflect.TypeOf(v)
|
tt = reflect.TypeOf(v)
|
||||||
vv = reflect.ValueOf(v)
|
vv = reflect.ValueOf(v)
|
||||||
|
@ -47,10 +47,7 @@ func ConvertToType(v interface{}, t Type) (interface{}, error) {
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case Map:
|
case Map:
|
||||||
var (
|
var (
|
||||||
res = reflect.MakeMapWithSize(
|
res = reflect.MakeMapWithSize(t, len(vv.MapKeys()))
|
||||||
t,
|
|
||||||
vv.Len(),
|
|
||||||
)
|
|
||||||
ck interface{}
|
ck interface{}
|
||||||
)
|
)
|
||||||
for _, k := range vv.MapKeys() {
|
for _, k := range vv.MapKeys() {
|
||||||
|
|
|
@ -2,13 +2,14 @@ package reflect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrCanNotConvertType struct {
|
type ErrCanNotConvertType struct {
|
||||||
value interface{}
|
value interface{}
|
||||||
from Type
|
from reflect.Type
|
||||||
to Type
|
to reflect.Type
|
||||||
reason []string
|
reason []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ func (e ErrCanNotConvertType) Error() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewErrCanNotConvertType(value interface{}, from Type, to Type, reason ...string) ErrCanNotConvertType {
|
func NewErrCanNotConvertType(value interface{}, from reflect.Type, to reflect.Type, reason ...string) ErrCanNotConvertType {
|
||||||
return ErrCanNotConvertType{
|
return ErrCanNotConvertType{
|
||||||
value: value,
|
value: value,
|
||||||
from: from,
|
from: from,
|
||||||
|
|
|
@ -12,14 +12,14 @@ func Indirect(v interface{}) interface{} {
|
||||||
return IndirectValue(reflect.ValueOf(v)).Interface()
|
return IndirectValue(reflect.ValueOf(v)).Interface()
|
||||||
}
|
}
|
||||||
|
|
||||||
func IndirectValue(reflectValue Value) Value {
|
func IndirectValue(reflectValue reflect.Value) reflect.Value {
|
||||||
if reflectValue.Kind() == reflect.Ptr {
|
if reflectValue.Kind() == reflect.Ptr {
|
||||||
return reflectValue.Elem()
|
return reflectValue.Elem()
|
||||||
}
|
}
|
||||||
return reflectValue
|
return reflectValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func IndirectType(reflectType Type) Type {
|
func IndirectType(reflectType reflect.Type) reflect.Type {
|
||||||
if reflectType == TypeInvalid {
|
if reflectType == TypeInvalid {
|
||||||
return TypeInvalid
|
return TypeInvalid
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,8 @@ var (
|
||||||
TypeOf = reflect.TypeOf
|
TypeOf = reflect.TypeOf
|
||||||
)
|
)
|
||||||
|
|
||||||
type Type = reflect.Type
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Types = []Type{
|
Types = []reflect.Type{
|
||||||
TypeBool,
|
TypeBool,
|
||||||
TypeInt,
|
TypeInt,
|
||||||
TypeInt8,
|
TypeInt8,
|
||||||
|
@ -31,7 +29,7 @@ var (
|
||||||
TypeString,
|
TypeString,
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeInvalid = Type(nil)
|
TypeInvalid = reflect.Type(nil)
|
||||||
TypeBool = reflect.TypeOf(false)
|
TypeBool = reflect.TypeOf(false)
|
||||||
TypeInt = reflect.TypeOf(int(0))
|
TypeInt = reflect.TypeOf(int(0))
|
||||||
TypeInt8 = reflect.TypeOf(int8(0))
|
TypeInt8 = reflect.TypeOf(int8(0))
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package reflect
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ValueOf = reflect.ValueOf
|
|
||||||
)
|
|
||||||
|
|
||||||
type Value = reflect.Value
|
|
Loading…
Reference in New Issue
Block a user