Refactor to Go standards; add print queue and own ESC/POS library
CI / Lint, test and scan (push) Successful in 1m41s

Restructure the daemon to follow the project's Go coding standards and
expand its features.

Layout and tooling
- cmd/uberbringer/main.go is now thin; all logic lives under internal/.
- Module path is git.anomalous.dev/57_Wolve/uberbringer, go 1.26, every
  dependency upgraded, vendor/ removed.
- staticcheck, govulncheck and goimports pinned as go tools; add a
  Makefile, CI workflow, goreleaser v2 config and Alpine Dockerfile.

Features
- Background print queue with job status (GET /api/v1/jobs/:id), send
  retries with backoff, and graceful shutdown.
- New {"elements": [...]} job format on POST /api/v1/print. Breaking:
  replaces {"data": [...]}, and the response is now JSON 202.
- In-house ESC/POS library replacing justinmichaelvieira/escpos: sizes
  1-8, Font B, CODE39/CODE128, QR, banded raster images, DLE EOT status.
- UTF-8 text transcoded to CP437 (configurable) with word-aware wrapping.
- Images from URL or base64, scaled and dithered; URL fetches refuse
  internal addresses (SSRF guard).
- Fiber v3 HTTP server, TypeID (UUIDv7) job and request IDs, /healthz
  with live printer status, `secret` and `token` subcommands.

Fixes
- Jobs are validated before anything is sent; a failed printer dial no
  longer panics.
- Request logs never contain tokens; Sentry no longer receives the
  Authorization header or print contents.
- Rate limiting is per client behind nginx (X-Real-IP).
- install.sh writes the [printer] section, runs the service as a
  dedicated user and uses a current nginx TLS config.

config.toml is no longer tracked; start from configs/config.example.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-29 21:17:16 -06:00
1 parent bb73348433
commit 6502d9551d
807 files changed
+6659 -500291

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
# Überbringer configuration.
#
# Copy to config.toml and fill in api.secret and printer.address; everything
# else is optional and shows its default. Durations use Go syntax: "500ms",
# "10s", "1m".
[webserver]
bind_ip = "127.0.0.1" # use "0.0.0.0" inside Docker
port = 8080
# Per-client rate limit on /api: rate_limit requests per rate_window.
rate_limit = 60
rate_window = "1m"
# Reverse proxies allowed to report the real client IP in proxy_header.
# install.sh configures nginx to set X-Real-IP.
trusted_proxies = ["127.0.0.1", "::1"]
proxy_header = "X-Real-IP"
body_limit = 4194304 # bytes (4 MiB); raise it for large base64 images
read_timeout = "15s"
write_timeout = "15s"
idle_timeout = "60s"
[api]
# HS256 key for bearer tokens, at least 32 bytes.
# Generate one with: uberbringer secret
# Then issue tokens: uberbringer token --subject my-script
secret = ""
[printer]
address = "" # printer IP or hostname, e.g. "192.168.1.245"
port = 9100
# tm-t20 (TM-T20/II/III), tm-t88 (TM-T88IV-VII), generic-80mm, generic-58mm
model = "tm-t20"
# Character table that text is transcoded to: cp437 (Epson default,
# box-drawing and shading), cp850, cp858 (adds €) or cp1252.
codepage = "cp437"
# paper_width = 576 # printable dots; overrides the model
# columns = 48 # Font A characters per line for word wrap
dial_timeout = "5s"
write_timeout = "30s"
retries = 3 # resend attempts when the printer is unreachable
retry_delay = "1s" # doubles after each attempt
[queue]
size = 100 # jobs that may wait; more get 503
history = 1000 # finished jobs whose status is kept
[images]
timeout = "10s"
max_bytes = 10485760 # 10 MiB download limit
max_pixels = 25000000 # decoded size limit (decompression bombs)
max_height = 4000 # printed height limit in dots, about 50 cm
# Image URLs that resolve to loopback, private or link-local addresses are
# refused unless allowed here. allowed_hosts, when set, is the only list of
# hosts images may come from, and those hosts may be on your LAN.
allow_private_networks = false
allowed_hosts = []
[sentry]
dsn = "" # falls back to SENTRY_DSN, then the build default
environment = "production"
debug = false
[log]
level = "info" # debug, info, warn or error
format = "text" # text or json