Ещё вариант:
package main
import (
"fmt"
"strconv"
)
func main() {
fmt.Println(interToInt64(1))
fmt.Println(interToInt64(int64(10)))
fmt.Println(interToInt64(int8(10)))
fmt.Println(interToInt64(15.5))
fmt.Println(interToInt64("15.5"))
fmt.Println(interToInt64("15"))
fmt.Println(interToInt64(uint(10)))
fmt.Println(interToInt64(uint64(999)))
fmt.Println(interToInt64(uint64(18446744073709551615)))
}
func interToInt64(inp interface{}) (int64, error) {
strVal := fmt.Sprint(inp)
if res, err := strconv.ParseInt(strVal, 10, 64); err == nil {
return res, nil
}
return 0, fmt.Errorf("unsupported type %T with value %v", inp, inp)
}
https://play.golang.org/p/Q0_5UIoU3KP