domain_api.go 591 B

12345678910111213141516171819202122232425262728
  1. package domain
  2. func GetTargetURL(shortURL string) (target string, err error) {
  3. su := ShortURL{URL: URL(shortURL)}
  4. tu, err := shortURLRepository.GetTarget(su)
  5. if err != nil {
  6. target = ""
  7. } else {
  8. target = string(tu.URL)
  9. }
  10. return
  11. }
  12. func GetShortURL(targetURL string) (short string, isNew bool, err error) {
  13. tu := TargetURL{URL: URL(targetURL)}
  14. if tu.IsEmpty() {
  15. // Zero values are OK for short and isNew.
  16. err = MakeError(TargetInvalidError, "empty URL")
  17. return
  18. }
  19. su, isNew, err := targetURLRepository.GetShort(tu)
  20. if err == nil {
  21. short = string(su.URL)
  22. }
  23. return
  24. }