Somthing like that?
type CardType string
const (
CTypePlastic CardType = "plastic"
CTypeVirtual CardType = "virtual"
)
type CardUsage string
const (
CUxBanking CardUsage = "banking"
CUxDiscount CardUsage = "discount"
CUxLoyality CardUsage = "loyality"
// ... any oather card ux
)
type CardPrepareFunc func() error
type CardTemplate struct {
cardType CardType
cardUx []CardUsage
cardPrepare []CardPrepareFunc
}
func (ct *CardTemplate) Print() error {
for _, pr := range ct.cardPrepare {
if err := pr(); err != nil {
return err
}
}
if ct.cardType == CTypePlastic {
// ct.sendToPrinter()
}
return nil
}
type CardOption = func(*CardTemplate) error
func WithCardUsage(cu CardUsage, f CardPrepareFunc) CardOption {
return func(ct *CardTemplate) error {
ct.cardUx = append(ct.cardUx, cu)
ct.cardPrepare = append(ct.cardPrepare, f)
return nil
}
}
func NewCardTemplate(opts ...CardOption) *CardTemplate {
ct := new(CardTemplate)
for _, opt := range opts {
opt(ct)
}
return ct
}