domain_spi.go 773 B

123456789101112131415161718192021222324252627282930
  1. package domain
  2. import (
  3. "github.com/nicksnyder/go-i18n/v2/i18n"
  4. )
  5. var shortURLRepository ShortURLRepository
  6. var targetURLRepository TargetURLRepository
  7. type ShortURLRepository interface {
  8. GetTarget(su ShortURL, localizer *i18n.Localizer) (TargetURL, error)
  9. }
  10. /*
  11. TargetURLRepository is the interface infrastructure needs to implement to
  12. provide the domain with access to Target URLs.
  13. */
  14. type TargetURLRepository interface {
  15. /*
  16. GetShort returns the ShortURL for a given TargetURL.
  17. In the results, isNew will be true if the ShortURL was created for this occasion.
  18. */
  19. GetShort(tu TargetURL) (su ShortURL, isNew bool, err error)
  20. }
  21. func RegisterRepositories(sur ShortURLRepository, tur TargetURLRepository) {
  22. shortURLRepository = sur
  23. targetURLRepository = tur
  24. }