AppendToSlice appends a value to a slice option. If the option does not exist, it creates a new slice with the value.
(o *Options, key string, value ...T)
| 106 | // AppendToSlice appends a value to a slice option. |
| 107 | // If the option does not exist, it creates a new slice with the value. |
| 108 | func AppendToSlice[T any](o *Options, key string, value ...T) { |
| 109 | if v, ok := o.m[key]; ok { |
| 110 | vt, ok := v.([]T) |
| 111 | if !ok { |
| 112 | panic(newTypeMismatchError(key, v, new([]T))) |
| 113 | } |
| 114 | |
| 115 | o.m[key] = append(vt, value...) |
| 116 | return |
| 117 | } |
| 118 | |
| 119 | o.m[key] = append([]T(nil), value...) |
| 120 | } |
| 121 | |
| 122 | // SliceContains checks if a slice option contains a specific value. |
| 123 | // If the option does not exist, it returns false. |