Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reetasingh/33be8581989961d43e93d338ad7ca11c to your computer and use it in GitHub Desktop.
Save reetasingh/33be8581989961d43e93d338ad7ca11c 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:43:5: db.save undefined (type *T is pointer to type parameter, not type parameter)
// ./prog.go:52:17: LocalDatabase does not satisfy PersonDB (method save has pointer receiver)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment