| 84 | } |
| 85 | |
| 86 | func ToStringKey(values ...interface{}) string { |
| 87 | results := make([]string, len(values)) |
| 88 | |
| 89 | for idx, value := range values { |
| 90 | if valuer, ok := value.(driver.Valuer); ok { |
| 91 | value, _ = valuer.Value() |
| 92 | } |
| 93 | |
| 94 | switch v := value.(type) { |
| 95 | case string: |
| 96 | results[idx] = v |
| 97 | case []byte: |
| 98 | results[idx] = string(v) |
| 99 | case uint: |
| 100 | results[idx] = strconv.FormatUint(uint64(v), 10) |
| 101 | default: |
| 102 | results[idx] = "nil" |
| 103 | vv := reflect.ValueOf(v) |
| 104 | if vv.IsValid() && !vv.IsZero() { |
| 105 | results[idx] = fmt.Sprint(reflect.Indirect(vv).Interface()) |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return strings.Join(results, "_") |
| 111 | } |
| 112 | |
| 113 | func Contains(elems []string, elem string) bool { |
| 114 | for _, e := range elems { |