I was trying to create a function that can take any type of datatype.
Here I will pass the variable which has contents but not the content directly.
func Anytype(buffer interface{}) error {
switch d := buffer.(type) {
case string:
fmt.Println("String")
case []byte:
fmt.Println("byte array")
}
return nil
}
func main(){
a:="string"
b:=[]byte{1,23,4}
Anytype(a)
Anytype(b)
}
But when I run this I am getting this error.How to solve this.
cannot convert str (type interface {}) to type string: need type assertion
Thanks