Created
July 5, 2023 00:11
-
-
Save reetasingh/c245a958b4bf2df100cc38ae34c73ea0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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