{"id":18023591,"url":"https://github.com/jeffotoni/printserver","last_synced_at":"2025-07-12T13:08:19.422Z","repository":{"id":134047486,"uuid":"98341416","full_name":"jeffotoni/printserver","owner":"jeffotoni","description":"A simple rest for receiving an encrypted POST, and responsible for printing a label on the Zebra printer in linux environment","archived":false,"fork":false,"pushed_at":"2017-08-18T11:39:39.000Z","size":2319,"stargazers_count":24,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T16:03:19.507Z","etag":null,"topics":["go","go-server","golang","golang-server","zebra-printer"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-25T19:15:26.000Z","updated_at":"2025-03-25T02:02:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"e42a0138-2e06-4c84-944f-6787ebc9e049","html_url":"https://github.com/jeffotoni/printserver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jeffotoni/printserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fprintserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fprintserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fprintserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fprintserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/printserver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fprintserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264995622,"owners_count":23694997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","go-server","golang","golang-server","zebra-printer"],"created_at":"2024-10-30T07:09:58.304Z","updated_at":"2025-07-12T13:08:19.402Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","readme":"# printserver\n\nA simple api rest to receive an encrypted POST and responsible for printing a label on the Zebra printer in the linux environment.\n\nWe will use the lpr native linux command to do the printing.\n\nThe way lpr works, in a nutshell, is: it reads in the file and hands the printable data over to the linux printing daemon, lpd. Lpd is a legacy piece of software for Unix and Linux, but it is supported under the modern system used by most Linux distributions, CUPS (the Common Unix Printing System).\n\nYou may need to manually install CUPS, and lpr itself, to print this way. If you are operating Debian, or a Debian-derived Linux system like Ubuntu that uses the APT package managements system, you can install them by running the following command:\n\nSudo apt-get update \u0026 \u0026 sudo apt-get install cups-client lpr\n\nThis command will install the Common Unix Printing System on your system. You should now be able to set up CUPS by directing any web browser to the address: http: // localhost: 631\n\nThe good thing is that we will send everything encrypted, but we can choose to encrypt the content before sending or not.\n\n\n# Packages\n\ngo get -u github.com/didip/tollbooth\n\ngo get -u github.com/dgrijalva/jwt-go\n\ngo get -u github.com/codegangsta/negroni\n\n\n# Install\n\n$ go build printserver.go\n\n$ sudo cp printserver /usr/bin\n\n# Generate the keys\n\n```sh\n\n$ openssl genrsa -out private.rsa 1024\n\n$ openssl rsa -in private.rsa -pubout \u003e public.rsa.pub\n\n```\n# Simulate \n\n```go\n\n$ go run test5_printserver.go\n\n$ go run test4_printserver.go\n\n$ go run test3_printserver.go\n\n$ go run test2_printserver.go\n\n$ go run test_printserver.go\n\n\n```\n\n# Simulate Curl\n\n```sh\n\n$ curl -X POST -H \"Content-Type: application/json\" \\\n\n-H \"Authorization: Basic MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM=:OTcyZGFkZGNhY2YyZmVhMjUzZmRhODY5NTY0ODUxMTU=\" \\\n\nlocalhost:9001/token\n\n$ curl -X POST -H \"Content-Type: application/json\" \\\n\n-H \"Authorization: Bearer \u003cTOKEN\u003e\" \\\n\nlocalhost:9001/ping\n\n$ curl -X POST -H \"Content-Type: application/x-www-form-urlencoded\" \\\n\n-H \"Authorization: Bearer \u003cTOKEN\u003e\" \\\n\n-d \"zpl='^xa^cfa,50^fo100,100^fdHello World!^fs^xz'\u0026code=000198\"\n\nlocalhost:9001/print\n\n```\n\n# Main function\n\n```go\n\nfunc main() {\n\n\t//\n\t//\n\t//\n\tcfg := Config()\n\n\t//\n\t//\n\t//\n\tShowScreen(cfg)\n\n\t// Creating limiter for all handlers\n\t// or one for each handler. Your choice.\n\t// This limiter basically says: allow at most NewLimiter request per 1 second.\n\tlimiter := tollbooth.NewLimiter(NewLimiter, time.Second)\n\n\t// Limit only GET and POST requests.\n\tlimiter.Methods = []string{\"GET\", \"POST\"}\n\n\t//\n\t//\n\t//\n\tmux := http.NewServeMux()\n\n\t// We had problem in doing method authentication and limit rate using negroni\n\t// mux.Handle(\"/ping\", negroni.New(negroni.HandlerFunc(MyMiddlewareAuth0), negroni.HandlerFunc(MyMiddlewarePing)))\n\n\tmux.Handle(HandlerPing, tollbooth.LimitFuncHandler(limiter, HandlerFuncAuth(auth0.HandlerValidate, Ping)))\n\n\tmux.Handle(HandlerV1Print, tollbooth.LimitFuncHandler(limiter, HandlerAuth(Print)))\n\n\t//\n\t// Off the default mux\n\t// Does not need authentication, only user key and token\n\t//\n\tmux.Handle(HandlerOauthToken, tollbooth.LimitFuncHandler(limiter, auth0.LoginBasic))\n\n\t// mux.Handle(\"/validate\", tollbooth.LimitFuncHandler(limiter, auth0.ValidateToken))\n\n\tnClassic := negroni.Classic()\n\n\tnClassic.UseHandler(mux)\n\n\t//\n\t//\n\t//\n\tconfServer = \u0026http.Server{\n\n\t\tAddr: \":\" + cfg.ServerPort,\n\n\t\tHandler: nClassic,\n\t\t//ReadTimeout:    30 * time.Second,\n\t\t//WriteTimeout:   20 * time.Second,\n\t\tMaxHeaderBytes: 1 \u003c\u003c 23, // Size accepted by package\n\t}\n\n\tlog.Fatal(confServer.ListenAndServe())\n\n}\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fprintserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fprintserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fprintserver/lists"}