package repository import ( "repo-pattern/app/repository/smartfilter" "gorm.io/gorm" "gorm.io/gorm/schema" ) type GetOptions struct { Only *[]string } type GetMethod[T schema.Tabler] struct { DbConn *gorm.DB } func (m *GetMethod[T]) Init(dbConn *gorm.DB) { m.DbConn = dbConn } func (m GetMethod[T]) Get(filter interface{}, options *GetOptions) (*T, error) { var ( model T ) query, err := smartfilter.ToQuery(model, filter, m.DbConn) if err != nil { return nil, err } if options != nil { query = applyOptionOnly(query, options.Only) } result := query.First(&model) if result.Error != nil { return nil, result.Error } return &model, nil }