Last active
June 25, 2022 15:13
-
-
Save thuan1412/588e09ee0acba6d8d09b3ba2ab388021 to your computer and use it in GitHub Desktop.
Dependency Injection in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment