32 lines
529 B
Go
32 lines
529 B
Go
package helpers
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
"strconv"
|
||
|
|
)
|
||
|
|
|
||
|
|
func Ask(str string) bool {
|
||
|
|
var input string
|
||
|
|
fmt.Printf("-> %s (Y/n): ", str)
|
||
|
|
fmt.Scanln(&input)
|
||
|
|
input = strings.TrimSpace(input)
|
||
|
|
input = strings.ToLower(input)
|
||
|
|
if input != "y" && input != "" && input != "yes" {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
|
||
|
|
func ToString(v interface{}) string {
|
||
|
|
switch val := v.(type) {
|
||
|
|
case int:
|
||
|
|
return strconv.Itoa(val)
|
||
|
|
case float64:
|
||
|
|
return strconv.FormatFloat(val, 'f', -1, 64)
|
||
|
|
case string:
|
||
|
|
return val
|
||
|
|
default:
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
}
|