-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
35 lines (32 loc) · 828 Bytes
/
Copy pathutil.go
File metadata and controls
35 lines (32 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ruleenginecore
import (
"fmt"
"strconv"
)
func parseValue(value string, toType ValueType) (any, *RuleEngineError) {
switch toType {
case Boolean:
if val, err := strconv.ParseBool(value); err != nil {
return nil, newError(ErrCodeParsingFailed, fmt.Sprintf("ParingError: %v", err))
} else {
return val, nil
}
case Integer:
if val, err := strconv.ParseInt(value, 10, 64); err != nil {
return nil, newError(ErrCodeParsingFailed, fmt.Sprintf("ParingError: %v", err))
} else {
return val, nil
}
case Float:
if val, err := strconv.ParseFloat(value, 64); err != nil {
return nil, newError(ErrCodeParsingFailed, fmt.Sprintf("ParingError: %v", err))
} else {
return val, nil
}
case String:
return value, nil
default:
// no-op
return nil, newError(ErrCodeInvalidValueType)
}
}