Skip to content

Instantly share code, notes, and snippets.

@thuan1412
Last active June 25, 2022 15:13
Show Gist options
  • Save thuan1412/588e09ee0acba6d8d09b3ba2ab388021 to your computer and use it in GitHub Desktop.
Save thuan1412/588e09ee0acba6d8d09b3ba2ab388021 to your computer and use it in GitHub Desktop.
Dependency Injection in Go
package main
import "fmt"
type IRepo interface {
Get() string
}
type Repo struct {
Name string
}
func (r Repo) Get() string {
return r.Name
}
func GetRepo(r IRepo) {
fmt.Println(r.Get())
}
func main() {
r := Repo{Name: "name"}
GetRepo(r) // output: name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment