Skip to content

Instantly share code, notes, and snippets.

@fenollp
Created April 29, 2018 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenollp/3709f48a69594fa0de4ac5e904a7c6e2 to your computer and use it in GitHub Desktop.
Save fenollp/3709f48a69594fa0de4ac5e904a7c6e2 to your computer and use it in GitHub Desktop.
Monkey patching idea in Golang
package main
import "fmt"
import "bytes"
func (* bytes.Buffer) Eh() string {
return "yay"
}
func main() {
fmt.Println("hey!")
fmt.Println(bytes.NewBuffer([]byte{}).Eh())
}
// ./monkey_patching.go:5:6: cannot define new methods on non-local type bytes.Buffer
// ./monkey_patching.go:11:39: bytes.NewBuffer([]byte literal).Eh undefined (type *bytes.Buffer has no field or method Eh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment