Skip to content

Instantly share code, notes, and snippets.

@zzerjae
Created October 31, 2020 08:10
Show Gist options
  • Save zzerjae/0e8feaefc86a5b38ea0d9c238bf63df2 to your computer and use it in GitHub Desktop.
Save zzerjae/0e8feaefc86a5b38ea0d9c238bf63df2 to your computer and use it in GitHub Desktop.
package main
type User struct {
id int64
name string
}
type DB interface {
GetUser(id int64) (*User, error)
}
type MemDB struct {}
func (m *MemDB) GetUser(id int64) (*User, error) {
...
}
type PostgreDB struct {}
func (p *PostgresDB) GetUser(id int64) (*User, error) {
...
}
func (p *PostgresDB) ListUsers(ids []int64) ([]*User, error) {
...
}
type Service struct {
db DB
}
fuc main() {
memDB := MemDB{}
postgreDB := PostgreDB{}
svc := Service{
db := &memDB // postgreDB로 대체 가능
}
...
}
@moonsub-kim
Copy link

32번째 줄에 typo가 있네요~ fuc -> func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment