- Overview
- Key-Features
- Architecture-Diagram
- Installation
- Usage-Example
- Supported-Protocols
- Roadmap
- Contributing
- License
POS Printer is a Go library that provides a unified, developer-friendly interface for communicating with a wide range of POS (Point of Sale) printer models. Designed with a clean and modular architecture, it simplifies the process of sending commands to thermal printers, whether you need to print text, generate QR codes, or render images. With comprehensive test coverage and support for multiple connection types, this library is built for reliability in production environments.
- Multi-Protocol Support: Native support for ESC/POS and ZPL, with an extensible architecture to add more.
- Flexible Connection Options: Connect to printers via Serial, USB, Network (TCP/IP), or Bluetooth.
- Protocol-Agnostic Image Printing: A powerful imaging package that handles direct bitmap generation from image files.
- Centralized Printer Registry: Manage multiple printer configurations in a centralized system, making it easy to switch between devices.
- Comprehensive Testing: Includes a full suite of unit tests, mocks, and fakes to ensure stable and predictable behavior.
- Well-Documented and Idiomatic Go: Clean, commented code that follows modern Go best practices.
The library is designed with a decoupled architecture, where each core functionality is separated into its own package. This allows for easy extension and maintenance.
graph TD
A[Application] --> B{pos Printer API}
subgraph "Core Library"
B --> C[Printer Registry]
B --> D[Connection Manager]
B --> E{Protocols}
end
subgraph "Connection Layer"
D --> F[USB]
D --> G[Network]
D --> H[Serial]
D --> I[Bluetooth]
end
subgraph "Protocols Layer"
E --> J[ESC/POS]
E --> K[ZPL]
E --> L[Imaging]
end
J --> M[Physical Printer]
K --> M
L --> M
To get started, add the library to your Go project using go get:
go get github.com/adcondev/pos-printerHere’s a simple example of how to connect to a printer and print a "Hello, World!" message.
package main
import (
"log"
"github.com/adcondev/pos-printer/escpos"
"github.com/adcondev/pos-printer/pos"
)
func main() {
// 1. Create a new printer profile in the registry
registry := pos.NewPrinterRegistry()
printerProfile := &pos.Printer{
Name: "MyReceiptPrinter",
Device: &pos.Device{
Connector: &pos.NetworkConnector{Address: "192.168.1.100:9100"},
},
}
registry.Add("my_printer", printerProfile)
// 2. Get the printer from the registry
p, err := registry.Get("my_printer")
if err != nil {
log.Fatalf("Failed to get printer: %v", err)
}
// 3. Connect to the printer
if err := p.Connect(); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer p.Close()
// 4. Send a command
cmd := escpos.NewPrinter(p.Device.Connector)
if err := cmd.Print("Hello, World!\n"); err != nil {
log.Fatalf("Failed to print: %v", err)
}
log.Println("Successfully printed!")
}| Protocol | Status | Description |
|---|---|---|
| ESC/POS | ✅ Stable | Epson Standard Code for Point of Sale Printers |
| ZPL | 🔄 In Progress | Zebra Programming Language for label printers |
| Image | ✅ Stable | Direct bitmap generation for any printer |
- Full support for the ZPL protocol.
- Add support for Bluetooth connections.
- Implement a more advanced logging system.
- Create a web-based interface for managing printers.
Contributions are welcome! If you'd like to help improve the library, please feel free to fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
