UD returns a UserData type for any given value.
(i interface{})
| 53 | |
| 54 | // UD returns a UserData type for any given value. |
| 55 | func UD(i interface{}) RedactorFunc { |
| 56 | switch v := i.(type) { |
| 57 | case string: |
| 58 | return func() Redactor { |
| 59 | return UserData(v) |
| 60 | } |
| 61 | case RedactorBuilder: |
| 62 | return func() Redactor { |
| 63 | return v.BuildRedactor(UD) |
| 64 | } |
| 65 | case fmt.Stringer: |
| 66 | return func() Redactor { |
| 67 | return UserData(v.String()) |
| 68 | } |
| 69 | case []byte: |
| 70 | return func() Redactor { |
| 71 | return UserData(string(v)) |
| 72 | } |
| 73 | default: |
| 74 | return func() Redactor { |
| 75 | valueOf := reflect.ValueOf(i) |
| 76 | if valueOf.Kind() == reflect.Slice { |
| 77 | return buildRedactorFuncSlice(valueOf, UD) |
| 78 | } |
| 79 | // Fall back to a slower but safe way of getting a string from any type. |
| 80 | return UserData(fmt.Sprintf("%+v", v)) |
| 81 | } |
| 82 | } |
| 83 | } |