Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Created August 8, 2014 01:45
Show Gist options
  • Save tenntenn/e86b4e1efb8353633a9c to your computer and use it in GitHub Desktop.
Save tenntenn/e86b4e1efb8353633a9c to your computer and use it in GitHub Desktop.
埋め込みを他のパッケージから隠蔽する #golang ref: http://qiita.com/tenntenn/items/f636b68ba5260cac2c92
type Fuga struct {
}
type Hoge struct {
*Fuga
}
// パッケージ外からもアクセスできる
hoge := &Hoge{&Fuga{}}
hoge.Fuga = nil
type fuga struct {
}
type Hoge struct {
*fuga
}
func NewHoge() *Hoge {
return &Hoge{&fuga{}}
}
// パッケージ外からはアクセスできない
hoge := pkg.NewHoge()
hoge.fuga = nil
type Fuga struct {
}
type fuga Fuga
type Hoge struct {
*fuga
}
func NewHoge() *Hoge {
return &Hoge{&fuga{}}
}
type stringer fmt.Stringer
type Hoge struct {
stringer
}
func NewHoge(s fmt.Stringer) *Hoge {
return &Hoge{stringer(s)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment