Skip to content

Instantly share code, notes, and snippets.

@CharlesWinter
Created January 22, 2021 15:13
Show Gist options
  • Select an option

  • Save CharlesWinter/a92701826c730411f184e33e7ed1a9bf to your computer and use it in GitHub Desktop.

Select an option

Save CharlesWinter/a92701826c730411f184e33e7ed1a9bf to your computer and use it in GitHub Desktop.
The repositories/customers/repository.go File
package customers
type Repository struct {
// This is where whatever the repository will use to access the DB will live
// as an unexported field. Nothing groundbreaking here.
somethingToAccessTheDB interface{}
}
// NewRepository will return a new instance of the customers.Repository. I've
// not outfitted it with actual DB connection logic so as to keep this article
// concise. The one takeaway here is that the DB accessor/provided should
// itself be injected, but that's out of the scope of this article.
func NewRepository(somethingToAccessTheDB interface{}) *Repository {
return &Repository{
somethingToAccessTheDB,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment