Skip to content

Instantly share code, notes, and snippets.

@masutaka
Last active September 19, 2017 15:57
Show Gist options
  • Save masutaka/e07517b2c6f8c8694d2296d05cceed05 to your computer and use it in GitHub Desktop.
Save masutaka/e07517b2c6f8c8694d2296d05cceed05 to your computer and use it in GitHub Desktop.
Maybe private method with golang
package main
import (
"fmt"
)
func main() {
fmt.Printf("main() in test.go\n")
new(Test).Hoge()
Test2.Hoge()
Test2.aaa() // compile error
}
type Test struct{}
func (t Test) Hoge() {
fmt.Printf("Hoge() in test.go\n")
}
package main
import "fmt"
type Test2Funcs interface {
Hoge()
}
var Test2 Test2Funcs = test2Funcs{}
type test2Funcs struct{}
func (t test2Funcs) Hoge() {
fmt.Printf("Hoge() in test2.go\n")
}
func (t test2Funcs) aaa() {
fmt.Printf("aaa() in test2.go\n")
}
@masutaka
Copy link
Author

$ go run *.go
# command-line-arguments
./test.go:11:7: Test2.aaa undefined (type Test2Funcs has no field or method aaa)

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