| 864 | } |
| 865 | |
| 866 | func (w *reflectWithString) resolve() error { |
| 867 | if w.v.Kind() == reflect.String { |
| 868 | w.s = w.v.String() |
| 869 | return nil |
| 870 | } |
| 871 | if tm, ok := w.v.Interface().(encoding.TextMarshaler); ok { |
| 872 | buf, err := tm.MarshalText() |
| 873 | w.s = string(buf) |
| 874 | return err |
| 875 | } |
| 876 | switch w.v.Kind() { |
| 877 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 878 | w.s = strconv.FormatInt(w.v.Int(), 10) |
| 879 | return nil |
| 880 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
| 881 | w.s = strconv.FormatUint(w.v.Uint(), 10) |
| 882 | return nil |
| 883 | } |
| 884 | panic("unexpected map key type") |
| 885 | } |
| 886 | |
| 887 | // NOTE: keep in sync with stringBytes below. |
| 888 | func (e *encodeState) string(s string, escapeHTML bool) { |