connection

package
v1.8.1-0...-f463bf0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package connection provides platform-specific printer connection implementations for ESC/POS printers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector interface {
	io.WriteCloser // Write([]byte) (int, error) y Close() error

}

Connector define la interfaz para cualquier tipo de conexión con la impresora

type PrinterDetail

type PrinterDetail struct {
	Name        string `json:"name"`
	Port        string `json:"port"`
	Driver      string `json:"driver"`
	Status      string `json:"status"`
	StatusRaw   uint32 `json:"status_raw,omitempty"`
	IsDefault   bool   `json:"is_default"`
	IsVirtual   bool   `json:"is_virtual"`
	PrinterType string `json:"printer_type"`
}

PrinterDetail stub for non-Windows platforms

func FilterPhysicalPrinters

func FilterPhysicalPrinters(_ []PrinterDetail) []PrinterDetail

FilterPhysicalPrinters stub

func FilterThermalPrinters

func FilterThermalPrinters(_ []PrinterDetail) []PrinterDetail

FilterThermalPrinters stub

func ListAvailablePrinters

func ListAvailablePrinters() ([]PrinterDetail, error)

ListAvailablePrinters is not available on non-Windows platforms

type PrinterService

type PrinterService interface {
	Open(name string) (uintptr, error)
	Close(handle uintptr) error
	StartDoc(handle uintptr, docName, dataType string) (uint32, error)
	EndDoc(handle uintptr) error
	AbortDoc(handle uintptr) error
	Write(handle uintptr, data []byte) (uint32, error)
}

PrinterService defines the interface for OS-specific printer operations. This allows mocking the low-level printer API for unit testing.

type PrinterState

type PrinterState = string

PrinterState stub

const (
	// StateReady indicates the printer is ready to accept jobs
	StateReady PrinterState = "ready"
	// StateOffline indicates the printer is offline
	StateOffline PrinterState = "offline"
	// StatePaused indicates the printer is paused
	StatePaused PrinterState = "paused"
	// StateError indicates the printer is in an error state
	StateError PrinterState = "error"
	// StateUnknown indicates the printer state is unknown
	StateUnknown PrinterState = "unknown"
)

type StubPrinterService

type StubPrinterService struct{}

StubPrinterService implements PrinterService for non-Windows platforms (always returns errors).

func (*StubPrinterService) AbortDoc

func (s *StubPrinterService) AbortDoc(_ uintptr) error

AbortDoc always returns an error indicating unavailability on non-Windows systems.

func (*StubPrinterService) Close

func (s *StubPrinterService) Close(_ uintptr) error

Close always returns an error indicating unavailability on non-Windows systems.

func (*StubPrinterService) EndDoc

func (s *StubPrinterService) EndDoc(_ uintptr) error

EndDoc always returns an error indicating unavailability on non-Windows systems.

func (*StubPrinterService) Open

func (s *StubPrinterService) Open(_ string) (uintptr, error)

Open always returns an error indicating unavailability on non-Windows systems.

func (*StubPrinterService) StartDoc

func (s *StubPrinterService) StartDoc(_ uintptr, _, _ string) (uint32, error)

StartDoc always returns an error indicating unavailability on non-Windows systems.

func (*StubPrinterService) Write

func (s *StubPrinterService) Write(_ uintptr, _ []byte) (uint32, error)

Write always returns an error indicating unavailability on non-Windows systems.

type WindowsPrintConnector

type WindowsPrintConnector struct {
	// contains filtered or unexported fields
}

WindowsPrintConnector implements a connector for Windows printers using the Windows API. It uses a PrinterService to abstract the underlying OS calls.

func NewWindowsPrintConnector

func NewWindowsPrintConnector(printerName string) (*WindowsPrintConnector, error)

NewWindowsPrintConnector creates a new connector for the specified printer name.

func (*WindowsPrintConnector) Close

func (c *WindowsPrintConnector) Close() error

Close ends the print job and closes the printer handle.

func (*WindowsPrintConnector) Read

func (c *WindowsPrintConnector) Read(buf []byte) (int, error)

Read implements the io.Reader interface but is not supported by the Windows Spooler API directly.

func (*WindowsPrintConnector) Write

func (c *WindowsPrintConnector) Write(data []byte) (int, error)

Write writes data to the printer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL