12345678910111213141516171819202122232425262728 |
- package domain
- func GetTargetURL(shortURL string) (target string, err error) {
- su := ShortURL{URL: URL(shortURL)}
- tu, err := shortURLRepository.GetTarget(su)
- if err != nil {
- target = ""
- } else {
- target = string(tu.URL)
- }
- return
- }
- func GetShortURL(targetURL string) (short string, isNew bool, err error) {
- tu := TargetURL{URL: URL(targetURL)}
- if tu.IsEmpty() {
- // Zero values are OK for short and isNew.
- err = MakeError(TargetInvalidError, "empty URL")
- return
- }
- su, isNew, err := targetURLRepository.GetShort(tu)
- if err == nil {
- short = string(su.URL)
- }
- return
- }
|