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(nil, TargetInvalid.Other, "empty URL") } // FIXME: will cause collisions. url := URL(strconv.Itoa(rand.Intn(1 << 31))) su = ShortURL{url, target} return su, nil }