1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package domain
- import (
- "github.com/nicksnyder/go-i18n/v2/i18n"
- )
- type MockShortRepo map[ShortURL]TargetURL
- func (sr MockShortRepo) GetTarget(su ShortURL, localizer *i18n.Localizer) (tu TargetURL, err error) {
- tu, ok := sr[su]
- if !ok {
- err = MakeError(localizer, ShortNotFound.ID, "")
- }
- 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(nil, ShortNotCreated.ID, "")
- }
- return
- }
- func MakeMockTargetRepo(create bool) MockTargetRepo {
- r := MockTargetRepo{
- Data: make(map[TargetURL]ShortURL),
- create: create,
- }
- return r
- }
|