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

Function getOmitEmpty

inception/encoder.go:42–78  ·  view source on GitHub ↗
(ic *Inception, sf *StructField)

Source from the content-addressed store, hash-verified

40}
41
42func getOmitEmpty(ic *Inception, sf *StructField) string {
43 ptname := "j." + sf.Name
44 if sf.Pointer {
45 ptname = "*" + ptname
46 return "if true {\n"
47 }
48 switch sf.Typ.Kind() {
49
50 case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
51 return "if len(" + ptname + ") != 0 {" + "\n"
52
53 case reflect.Int,
54 reflect.Int8,
55 reflect.Int16,
56 reflect.Int32,
57 reflect.Int64,
58 reflect.Uint,
59 reflect.Uint8,
60 reflect.Uint16,
61 reflect.Uint32,
62 reflect.Uint64,
63 reflect.Uintptr,
64 reflect.Float32,
65 reflect.Float64:
66 return "if " + ptname + " != 0 {" + "\n"
67
68 case reflect.Bool:
69 return "if " + ptname + " != false {" + "\n"
70
71 case reflect.Interface, reflect.Ptr:
72 return "if " + ptname + " != nil {" + "\n"
73
74 default:
75 // TODO(pquerna): fix types
76 return "if true {" + "\n"
77 }
78}
79
80func getMapValue(ic *Inception, name string, typ reflect.Type, ptr bool, forceString bool) string {
81 var out = ""

Callers 1

getFieldFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…