interface to int golang code example
Example 1: golang convert interface to concrete type
type Person struct {
firstName string
lastName string
}
func printIfPerson(object interface{}) {
person, ok := object.(Person)
if ok {
fmt.Printf("Hello %s!\n", person.firstName)
}
}
Example 2: interfaces in golang
The interface is a collection of methods as well as it is a custom type.
Example 3: interface to int golang
iAreaId := val.(int)
iAreaId, ok := val.(int) // Alt. non panicking version