Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Created December 13, 2019 11:53
Show Gist options
  • Save paulohrpinheiro/2a1b64319dde4f8c109017dbd95f8629 to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/2a1b64319dde4f8c109017dbd95f8629 to your computer and use it in GitHub Desktop.
Working with unknown types in go
package main
import "fmt"
// Void - a generic type
type Void struct {
value interface{}
}
func work(universe map[int]interface{}, v Void) {
value := v.value
switch t := value.(type) {
default:
fmt.Println("Unknow", t)
case int:
universe[1] = v
}
}
func main() {
myInt := 100
data := Void{}
data.value = myInt
universe := make(map[int]interface{})
work(universe, data)
fmt.Println(universe)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment