Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reetasingh/961d1dad62b5359fb7bc0704876c8b3e to your computer and use it in GitHub Desktop.
Save reetasingh/961d1dad62b5359fb7bc0704876c8b3e to your computer and use it in GitHub Desktop.
func CreatePersonDB[T PersonDB](person Person) error {
db := new(T)
db.save(person)
return nil
}
func main() {
person := Person{
ID: 101,
Name: "John D",
}
CreatePersonDB[*LocalDatabase](person)
}
// will not compile
// ./prog.go:42:5: db.save undefined (type *T is pointer to type parameter, not type parameter)
Go build failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment