package printer import ( "fmt" "io" "os" "os/exec" ) type Printer struct { devicePath string } func New(devicePath string) *Printer { return &Printer{ devicePath: devicePath, } } func (p *Printer) PrintText(text string) error { lp, err := os.OpenFile(p.devicePath, os.O_WRONLY, 0) if err != nil { return fmt.Errorf("failed to open: %v", err) } defer lp.Close() cmd := exec.Command("./printtext", text) cmd.Stdout = lp return cmd.Run() } func (p *Printer) PrintImage(data io.Reader, caption string) error { cmd := exec.Command("./printimg", p.devicePath, caption) cmd.Stdin = data return cmd.Run() }