Skip to content

Instantly share code, notes, and snippets.

@olix0r
Created April 7, 2015 20:59
Show Gist options
  • Save olix0r/03c6e6ae30befc79abc2 to your computer and use it in GitHub Desktop.
Save olix0r/03c6e6ae30befc79abc2 to your computer and use it in GitHub Desktop.
Adapters in go
package main
type Goaled interface {
Goaled() bool
}
type Sane interface {
Sane() bool
}
func (goaled Goaled) Sane() bool {
return !goaled.Goaled()
}
func main() {
}
package main
type Goaled interface {
Goaled() bool
}
type Sane interface {
Sane() bool
}
type saneGoaled struct{goaled Goaled}
func (sg *saneGoaled) Sane() bool {
return !sg.goaled.Goaled()
}
func main() {
}
@olix0r
Copy link
Author

olix0r commented Apr 7, 2015

Adapters in Go

fooer_bad.go fails to compile:

/tmp/sandbox152930166/main.go:11: invalid receiver type Goaled (Goaled is an interface type)

fooer_dumb.go compiles but has a dumb pointless adapter type.

Is there a more graceful solution to adapters in Go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment