MCPcopy
hub / github.com/pquerna/ffjson / getXValue

Function getXValue

tests/ff_test.go:407–428  ·  view source on GitHub ↗
(thing interface{})

Source from the content-addressed store, hash-verified

405}
406
407func getXValue(thing interface{}) interface{} {
408 v := reflect.ValueOf(thing)
409 v = reflect.Indirect(v)
410 f := v.FieldByName("X")
411 switch f.Kind() {
412 case reflect.Bool:
413 return f.Bool()
414 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
415 return f.Int()
416 case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
417 return f.Uint()
418 case reflect.Float32, reflect.Float64:
419 return f.Float()
420 case reflect.String:
421 return f.String()
422 }
423
424 var buf bytes.Buffer
425 enc := gob.NewEncoder(&buf)
426 enc.Encode(f)
427 return buf.String()
428}
429
430func TestArray(t *testing.T) {
431 testType(t, &Tarray{X: [3]int{}}, &Xarray{X: [3]int{}})

Callers 2

testExpectedXFunction · 0.85
testExpectedXValBareFunction · 0.85

Calls 3

EncodeMethod · 0.95
StringMethod · 0.95
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…