Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reetasingh/c245a958b4bf2df100cc38ae34c73ea0 to your computer and use it in GitHub Desktop.
Save reetasingh/c245a958b4bf2df100cc38ae34c73ea0 to your computer and use it in GitHub Desktop.
type DBType interface {
LocalDatabase | InMemoryDatabase
}
type DBPointer[T any] interface {
*T
PersonDB
}
func CreatePersonDB[T DBType, dbPointer DBPointer[T]](person Person) error {
var db dbPointer = new(T)
db.save(person)
return nil
}
func main() {
person := Person{
ID: 101,
Name: "John D",
}
CreatePersonDB[LocalDatabase](person)
CreatePersonDB[InMemoryDatabase](person)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment