Create some subroutines and test
This commit is contained in:
22
src/game/rule/operation/convert.go
Normal file
22
src/game/rule/operation/convert.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package operation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func convertNumber(v interface{}) int {
|
||||
s := fmt.Sprint(v)
|
||||
v2, _ := strconv.ParseFloat(s, 64)
|
||||
return int(v2)
|
||||
}
|
||||
|
||||
func convertString(v interface{}) string {
|
||||
switch v.(type) {
|
||||
case string:
|
||||
return v.(string)
|
||||
case []byte:
|
||||
return string(v.([]byte))
|
||||
}
|
||||
return fmt.Sprint(v)
|
||||
}
|
||||
Reference in New Issue
Block a user