File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ func FloatToStringConverter[T Float](from T) (to string) {
16
16
}
17
17
18
18
// StringToIntConverter parses int from string
19
+ //
20
+ // On error returns default value (0)
19
21
func StringToIntConverter [T Int ](from string ) (to T ) {
20
22
n , err := strconv .Atoi (from )
21
23
if err != nil {
@@ -24,7 +26,20 @@ func StringToIntConverter[T Int](from string) (to T) {
24
26
return T (n )
25
27
}
26
28
29
+ // MustStringToIntConverter parses int from string
30
+ //
31
+ // On error panics
32
+ func MustStringToIntConverter [T Int ](from string ) (to T ) {
33
+ n , err := strconv .Atoi (from )
34
+ if err != nil {
35
+ panic (err )
36
+ }
37
+ return T (n )
38
+ }
39
+
27
40
// StringToIntConverter parses float from string
41
+ //
42
+ // On error returns default value (0)
28
43
func StringToFloatConverter [T Float ](from string ) (to T ) {
29
44
const bitSize = 64
30
45
n , err := strconv .ParseFloat (from , bitSize )
@@ -33,3 +48,15 @@ func StringToFloatConverter[T Float](from string) (to T) {
33
48
}
34
49
return T (n )
35
50
}
51
+
52
+ // MustStringToFloatConverter parses float from string
53
+ //
54
+ // On error panics
55
+ func MustStringToFloatConverter [T Float ](from string ) (to T ) {
56
+ const bitSize = 64
57
+ n , err := strconv .ParseFloat (from , bitSize )
58
+ if err != nil {
59
+ panic (err )
60
+ }
61
+ return T (n )
62
+ }
You can’t perform that action at this time.
0 commit comments