mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
27 lines
470 B
Go
27 lines
470 B
Go
package dynamic
|
|
|
|
import "reflect"
|
|
|
|
func HasField(rs reflect.Value, fieldName string) (field reflect.Value, ok bool) {
|
|
field = rs.FieldByName(fieldName)
|
|
return field, field.IsValid()
|
|
}
|
|
|
|
func LookupSymbolField(rs reflect.Value) (string, bool) {
|
|
if rs.Kind() == reflect.Ptr {
|
|
rs = rs.Elem()
|
|
}
|
|
|
|
field := rs.FieldByName("Symbol")
|
|
if !field.IsValid() {
|
|
return "", false
|
|
}
|
|
|
|
if field.Kind() != reflect.String {
|
|
return "", false
|
|
}
|
|
|
|
return field.String(), true
|
|
}
|
|
|