Skip to content

Instantly share code, notes, and snippets.

@pulkitkumar
Last active August 7, 2018 02:21
Show Gist options
  • Save pulkitkumar/cb55214a7cf2badc2da45d658dc2df34 to your computer and use it in GitHub Desktop.
Save pulkitkumar/cb55214a7cf2badc2da45d658dc2df34 to your computer and use it in GitHub Desktop.
OOP Semantics
package user
import (
"io"
)
type User struct {
Name string
Email string
}
type UserRepository interface {
Read() ([]User, error)
Write([]User) error
}
type defaultUserRepository struct {
rdr io.Reader
wtr io.WriteCloser
}
func (u *defaultUserRepository) Read() ([]User, error) {
// read using reader u.rdr
//u.rdr.Read()
return []User{}, nil
}
func (u *defaultUserRepository) Write(usr []User) error {
// write using u.wtr
//u.wtr.Write(...)
return nil
}
func CreateUserRepository(r io.Reader, w io.WriteCloser) UserRepository {
repo := defaultUserRepository{
rdr: r,
wtr: w,
}
return &repo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment