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