123456789101112131415161718192021222324252627282930 |
- package domain
- import (
- "math/rand"
- "strconv"
- )
- type ShortURL struct {
- URL
- target TargetURL
- }
- func (su ShortURL) Target() TargetURL {
- return su.target
- }
- /*
- MakeShortURL creates a ShortURL instance from a given RedirectURL/target pair.
- */
- func NewUnspecifiedShortURL(target TargetURL) (ShortURL, error) {
- var su ShortURL
- if target.IsEmpty() {
- return su, MakeError(TargetInvalidError, "empty URL")
- }
- // FIXME: will cause collisions.
- url := URL(strconv.Itoa(rand.Intn(1 << 31)))
- su = ShortURL{url, target}
- return su, nil
- }
|