12345678910111213141516171819202122232425262728293031323334353637383940 |
- package domain
- type MockShortRepo map[ShortURL]TargetURL
- func (sr MockShortRepo) GetTarget(su ShortURL) (tu TargetURL, err error) {
- tu, ok := sr[su]
- if !ok {
- err = MakeError(ShortNotFound, "")
- }
- return
- }
- type MockTargetRepo struct {
- Data map[TargetURL]ShortURL
- create bool
- }
- func (tr MockTargetRepo) GetShort(tu TargetURL) (su ShortURL, isNew bool, err error) {
- su, ok := tr.Data[tu]
- if ok {
- return
- }
- if tr.create {
- su = ShortURL{URL: tu.URL, target: tu}
- tr.Data[tu] = su
- isNew = true
- } else {
- err = MakeError(ShortNotCreated, "")
- }
- return
- }
- func MakeMockTargetRepo(create bool) MockTargetRepo {
- r := MockTargetRepo{
- Data: make(map[TargetURL]ShortURL),
- create: create,
- }
- return r
- }
|