(ic *Inception, name string, typ reflect.Type, ptr bool, forceString bool)
| 78 | } |
| 79 | |
| 80 | func getMapValue(ic *Inception, name string, typ reflect.Type, ptr bool, forceString bool) string { |
| 81 | var out = "" |
| 82 | |
| 83 | if typ.Key().Kind() != reflect.String { |
| 84 | out += fmt.Sprintf("/* Falling back. type=%v kind=%v */\n", typ, typ.Kind()) |
| 85 | out += ic.q.Flush() |
| 86 | out += "err = buf.Encode(" + name + ")" + "\n" |
| 87 | out += "if err != nil {" + "\n" |
| 88 | out += " return err" + "\n" |
| 89 | out += "}" + "\n" |
| 90 | return out |
| 91 | } |
| 92 | |
| 93 | var elemKind reflect.Kind |
| 94 | elemKind = typ.Elem().Kind() |
| 95 | |
| 96 | switch elemKind { |
| 97 | case reflect.String, |
| 98 | reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, |
| 99 | reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, |
| 100 | reflect.Float32, |
| 101 | reflect.Float64, |
| 102 | reflect.Bool: |
| 103 | |
| 104 | ic.OutputImports[`fflib "github.com/pquerna/ffjson/fflib/v1"`] = true |
| 105 | |
| 106 | out += "if " + name + " == nil {" + "\n" |
| 107 | ic.q.Write("null") |
| 108 | out += ic.q.GetQueued() |
| 109 | ic.q.DeleteLast() |
| 110 | out += "} else {" + "\n" |
| 111 | out += ic.q.WriteFlush("{ ") |
| 112 | out += " for key, value := range " + name + " {" + "\n" |
| 113 | out += " fflib.WriteJsonString(buf, key)" + "\n" |
| 114 | out += " buf.WriteString(`:`)" + "\n" |
| 115 | out += getGetInnerValue(ic, "value", typ.Elem(), false, forceString) |
| 116 | out += " buf.WriteByte(',')" + "\n" |
| 117 | out += " }" + "\n" |
| 118 | out += "buf.Rewind(1)" + "\n" |
| 119 | out += ic.q.WriteFlush("}") |
| 120 | out += "}" + "\n" |
| 121 | |
| 122 | default: |
| 123 | out += ic.q.Flush() |
| 124 | out += fmt.Sprintf("/* Falling back. type=%v kind=%v */\n", typ, typ.Kind()) |
| 125 | out += "err = buf.Encode(" + name + ")" + "\n" |
| 126 | out += "if err != nil {" + "\n" |
| 127 | out += " return err" + "\n" |
| 128 | out += "}" + "\n" |
| 129 | } |
| 130 | return out |
| 131 | } |
| 132 | |
| 133 | func getGetInnerValue(ic *Inception, name string, typ reflect.Type, ptr bool, forceString bool) string { |
| 134 | var out = "" |
no test coverage detected
searching dependent graphs…