Working version
This commit is contained in:
29
app/repository/repository.go
Normal file
29
app/repository/repository.go
Normal file
@ -0,0 +1,29 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/schema"
|
||||
)
|
||||
|
||||
type MethodInitInterface interface {
|
||||
Init(dbConn *gorm.DB)
|
||||
}
|
||||
|
||||
type RepoBase[T schema.Tabler] struct {
|
||||
DbConn int
|
||||
ListMethod[T]
|
||||
GetMethod[T]
|
||||
ExistsMethod[T]
|
||||
methods []MethodInitInterface
|
||||
}
|
||||
|
||||
func (b *RepoBase[T]) InitMethods(dbConn *gorm.DB) {
|
||||
for _, method := range b.methods {
|
||||
method.Init(dbConn)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *RepoBase[T]) Init(dbConn *gorm.DB) {
|
||||
m.methods = []MethodInitInterface{&m.ListMethod, &m.GetMethod, &m.ExistsMethod}
|
||||
m.InitMethods(dbConn)
|
||||
}
|
||||
Reference in New Issue
Block a user