Files
repo-pattern/app/repository/repository.go
2024-06-22 13:34:27 +02:00

30 lines
535 B
Go

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)
}