| 10 | type textValue struct{ p encoding.TextUnmarshaler } |
| 11 | |
| 12 | func newTextValue(val encoding.TextMarshaler, p encoding.TextUnmarshaler) textValue { |
| 13 | ptrVal := reflect.ValueOf(p) |
| 14 | if ptrVal.Kind() != reflect.Ptr { |
| 15 | panic("variable value type must be a pointer") |
| 16 | } |
| 17 | defVal := reflect.ValueOf(val) |
| 18 | if defVal.Kind() == reflect.Ptr { |
| 19 | defVal = defVal.Elem() |
| 20 | } |
| 21 | if defVal.Type() != ptrVal.Type().Elem() { |
| 22 | panic(fmt.Sprintf("default type does not match variable type: %v != %v", defVal.Type(), ptrVal.Type().Elem())) |
| 23 | } |
| 24 | ptrVal.Elem().Set(defVal) |
| 25 | return textValue{p} |
| 26 | } |
| 27 | |
| 28 | func (v textValue) Set(s string) error { |
| 29 | return v.p.UnmarshalText([]byte(s)) |