convertToFloat converts an interface to a float64
(Value interface{})
| 165 | |
| 166 | // convertToFloat converts an interface to a float64 |
| 167 | func convertToFloat(Value interface{}) (float64, error) { |
| 168 | switch value := Value.(type) { |
| 169 | case int: |
| 170 | return float64(value), nil |
| 171 | case uint: |
| 172 | return float64(value), nil |
| 173 | case float32: |
| 174 | return float64(value), nil |
| 175 | case float64: |
| 176 | return value, nil |
| 177 | case string: |
| 178 | floatValue, err := strconv.ParseFloat(value, 64) |
| 179 | if err != nil { |
| 180 | return 0, err |
| 181 | } |
| 182 | return floatValue, nil |
| 183 | case []byte: |
| 184 | strValue := string(value) |
| 185 | floatValue, err := strconv.ParseFloat(strValue, 64) |
| 186 | if err != nil { |
| 187 | return 0, err |
| 188 | } |
| 189 | return floatValue, nil |
| 190 | default: |
| 191 | return 0, errors.New("unsupported type") |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | func convertToRegexp(pattern string) string { |
| 196 | // 转义正则特殊字符 |