Go - Generic function using an interface
Posted
by nevalu
on Stack Overflow
See other posts from Stack Overflow
or by nevalu
Published on 2010-05-09T10:10:01Z
Indexed on
2010/05/09
10:18 UTC
Read the original article
Hit count: 227
Since I've a similar function for 2 different data types:
func GetStatus(value uint8) (string) {...}
func GetStatus(name string) (string) {...}
I would want to use a way more simple like:
func GetStatus(value interface{}) (string) {...}
Is possible to create a generic function using an interface?
The data type could be checked using reflect.Typeof(value)
© Stack Overflow or respective owner