mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-08-03 13:12:16 +02:00
initial import
This commit is contained in:
28
best-practices/single-method-interface/main.go
Normal file
28
best-practices/single-method-interface/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Log(message string)
|
||||
}
|
||||
|
||||
type LoggerFunc func(message string)
|
||||
|
||||
func (l LoggerFunc) Log(message string) {
|
||||
l(message)
|
||||
}
|
||||
|
||||
func MyLogFunc(message string) {
|
||||
fmt.Printf("I log %s\n", message)
|
||||
}
|
||||
|
||||
func myMethodTakesTheLog(l Logger) {
|
||||
l.Log("my log message")
|
||||
}
|
||||
|
||||
func main() {
|
||||
logger := LoggerFunc(MyLogFunc)
|
||||
myMethodTakesTheLog(logger)
|
||||
}
|
Reference in New Issue
Block a user