Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created December 14, 2014 13:28
Show Gist options
  • Save iporsut/aab570907a2d71bfbc28 to your computer and use it in GitHub Desktop.
Save iporsut/aab570907a2d71bfbc28 to your computer and use it in GitHub Desktop.
Spike Logger Go
package main
import "fmt"
type Logger interface {
log(message string)
}
type DefaultLogger struct {
}
func (dl *DefaultLogger) log(message string) {
fmt.Println(message)
}
type IA interface {
A()
}
type IALogger struct {
IA
Logger
}
func (l *IALogger) A() {
l.Logger.log("Begin A")
l.IA.A()
l.Logger.log("End A")
}
type IB interface {
B()
}
type IBLogger struct {
IB
Logger
}
func (l *IBLogger) B() {
l.Logger.log("Begin B")
l.IB.B()
l.Logger.log("End B")
}
type IC interface {
C()
}
type ICLogger struct {
IC
Logger
}
func (l *ICLogger) C() {
l.Logger.log("Begin C")
l.IC.C()
l.Logger.log("End C")
}
type ABCImp struct {
}
func (a *ABCImp) A() {
fmt.Println("Method A")
}
func (b *ABCImp) B() {
fmt.Println("Method B")
}
func (c *ABCImp) C() {
fmt.Println("Method C")
}
func main() {
var ia IA
var ib IB
var ic IC
abc := &ABCImp{}
ia = &IALogger{abc, &DefaultLogger{}}
ia.A()
ib = &IBLogger{abc, &DefaultLogger{}}
ib.B()
ic = &ICLogger{abc, &DefaultLogger{}}
ic.C()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment