Skip to content

Instantly share code, notes, and snippets.

@Mo3g4u
Created August 19, 2022 05:06
Show Gist options
  • Save Mo3g4u/6adf7bd3c1d1d080c8aaf37c79a2cd16 to your computer and use it in GitHub Desktop.
Save Mo3g4u/6adf7bd3c1d1d080c8aaf37c79a2cd16 to your computer and use it in GitHub Desktop.
構造体を利用したオプション引数
package main
// 構造体を利用したオプション引数
import "fmt"
type Portion int
const (
Regular Portion = iota
Small
Large
)
type Udon struct {
men Portion
aburaage bool
ebiten uint
}
type Option struct {
men Portion
aburaage bool
ebiten uint
}
func NewUdon(opt Option) *Udon {
return &Udon{
men: opt.men,
aburaage: opt.aburaage,
ebiten: opt.ebiten,
}
}
func main() {
tempuraUdon := NewUdon(Option{
men: Large,
aburaage: false,
ebiten: 2,
})
fmt.Printf("%#v\n", tempuraUdon)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment