The compile error you're seeing is exactly what is happening. That var alive bool
is unused. You declare it and assign a value to it but you never do anything with it.
Here is a playground-friendly modification of your code that will run:
package main
import (
"fmt"
"strconv"
)
func main() {
fmt.Println(isInt("Hello, playground")) // prints false
fmt.Println(isInt("1234567890")) // prints true
}
func isInt(s string) bool {
var alive bool
_, err := strconv.Atoi(s) // simply to demonstrate an error case
if err != nil {
alive = false
} else {
alive = true
}
return alive
}
Notice that I return alive. The function is useless and not something I would suggest in and of itself but it should help illustrate what is missing in your example.