SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package mocks
  2.  
  3. import (
  4.     "errors"
  5.     "strconv"
  6.  
  7.     "github.com/###/pkg/entity"
  8. )
  9.  
  10. type IRepo struct {
  11.     users map[string]*entity.User
  12. }
  13.  
  14. func NewInmemUserRepository() *IRepo {
  15.     var users = map[string]*entity.User{}
  16.     return &IRepo{users}
  17. }
  18.  
  19. func (r *IRepo) Create(u *entity.User) error {
  20.     strID := strconv.Itoa(int(u.ID))
  21.  
  22.     if _, ok := r.users[strID]; ok {
  23.         return errors.New("Users with id: " + strID + " exists")
  24.     }
  25.  
  26.     r.users[strID] = u
  27.     return nil
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top