Skip to content

Instantly share code, notes, and snippets.

@J7mbo
Created February 22, 2019 12:07
Show Gist options
  • Save J7mbo/3c392f43616030e1e5e9fc568fd5ffd8 to your computer and use it in GitHub Desktop.
Save J7mbo/3c392f43616030e1e5e9fc568fd5ffd8 to your computer and use it in GitHub Desktop.
golang-constructors-blog-6
package Package1
/* The interface is exported, so publically available */
type MyStructsInterface interface {
SomeInterfaceMethod() int
}
/* Private struct */
type myStruct struct {
num int
}
func NewMyStruct() myStruct {
return MyStruct{num: 22}
}
/* With this, myStruct now implicitly implements MyStructsInterface */
func (*myStruct) SomeInterfaceMethod() int {
return 42
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment