Created
August 19, 2022 05:06
-
-
Save Mo3g4u/6adf7bd3c1d1d080c8aaf37c79a2cd16 to your computer and use it in GitHub Desktop.
構造体を利用したオプション引数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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