gobuch/best-practices/single-method-interface/main.go
2020-08-21 06:26:40 +02:00

29 lines
390 B
Go

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)
}