Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e5f67ce
add qr-gen
TOsmanov May 6, 2024
45eb40e
add tests
TOsmanov May 18, 2024
a5e2ac6
update README.md
TOsmanov May 18, 2024
39b4863
update go.mod
TOsmanov May 18, 2024
418a93f
fix tests
TOsmanov May 18, 2024
30cd334
add docker compose
TOsmanov May 19, 2024
b1931b5
update all
TOsmanov May 20, 2024
f75ed43
remove uncessary
TOsmanov May 21, 2024
45bcd2c
add github actions
TOsmanov May 21, 2024
e9d8cee
fix and update README.md
TOsmanov May 21, 2024
4d6faaf
fix lint errors
TOsmanov May 21, 2024
72c2016
remove uncessary and fix lint errors
TOsmanov May 21, 2024
2fa3f45
fix lint errors
TOsmanov May 21, 2024
130a6e9
fix test
TOsmanov May 21, 2024
289ba4d
fix .golangci.yml
TOsmanov May 21, 2024
ca43ce0
bump lint action
TOsmanov May 21, 2024
c520f76
fix tests
TOsmanov May 21, 2024
e723ae2
fix lint errors
TOsmanov May 21, 2024
d0b6818
fix lint errors
TOsmanov May 21, 2024
ce9812c
update .golangci.yml
TOsmanov May 21, 2024
53b34dc
disable depguard
TOsmanov May 21, 2024
fa41f93
disable deprecated linters
TOsmanov May 21, 2024
692d9e1
add a format validation
TOsmanov May 24, 2024
d0f05de
add cleaner
TOsmanov May 25, 2024
3d176bf
fix linter error
TOsmanov May 25, 2024
de1a8a4
fix linter error
TOsmanov May 25, 2024
3c2d710
fix output filenames
TOsmanov May 25, 2024
909fc9c
update main page
TOsmanov May 25, 2024
94c17a9
fix negative parameter values
TOsmanov May 27, 2024
2f01042
fix
TOsmanov May 28, 2024
a5312c9
fix main page
TOsmanov May 28, 2024
b190562
fix validation numeric parameters
TOsmanov May 28, 2024
5d68bbe
update server and cli
TOsmanov May 29, 2024
2d11094
update linter
TOsmanov May 29, 2024
9fc67ed
update and fix
TOsmanov May 31, 2024
bf5e4cb
update timezone and port
TOsmanov Jun 3, 2024
5145a3b
fix index.html
TOsmanov Jun 3, 2024
2d8d44c
add text tests
TOsmanov Jun 3, 2024
191e553
update tests
TOsmanov Jun 3, 2024
130e016
fix tests and lint
TOsmanov Jun 4, 2024
a138873
fix tests
TOsmanov Jun 4, 2024
b07e2c9
add tests
TOsmanov Jun 4, 2024
416038d
fix log
TOsmanov Jun 4, 2024
e7d3c7e
add clean
TOsmanov Jun 4, 2024
013c642
update main page
TOsmanov Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: QR-gen tests

on:
push:
branches:
- add*

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Extract branch name
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Check out code
uses: actions/checkout@v4

- name: Linters
uses: golangci/golangci-lint-action@v6
with:
version: v1.58

tests:
runs-on: ubuntu-latest
steps:
- name: Extract branch name
run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ^1.21.5

- name: Check out code
uses: actions/checkout@v3

- name: Unit tests
run: go test -v -count=1 -race -timeout=1m ./...
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output/
tests/output/
tests/fonts/
tests/archive.zip
temp/
site/preview.jpg
*.exe
85 changes: 85 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
run:
tests: true

linters-settings:
funlen:
lines: 150
statements: 80
depguard:
rules:
main:
files:
- $all
- "!$test"
allow:
- $gostd
- github.com/skip2
- github.com/fogleman
- github.com/go-chi
- github.com/TOsmanov
- github.com/ilyakaznacheev
- github.com/go-playground
test:
files:
- "$test"
allow:
- $gostd
- github.com/stretchr

linters:
disable-all: true
enable:
- asciicheck
- bodyclose
# - deadcode
- depguard
- dogsled
- dupl
- durationcheck
- errorlint
- exhaustive
- exportloopref
- funlen
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- gofumpt
- goheader
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
# - ifshort
- importas
- ineffassign
- lll
- makezero
- misspell
- nestif
- nilerr
- noctx
- nolintlint
- prealloc
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
# - structcheck
- stylecheck
- tagliatelle
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
# - varcheck
- wastedassign
- whitespace
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:latest AS builder
COPY ./ /usr/local/go/src/qr_gen/
WORKDIR /usr/local/go/src/qr_gen
RUN go clean --modcache && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-mod=readonly -o qrgen /usr/local/go/src/qr_gen/server/main.go
FROM scratch
WORKDIR /app
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/local/go/src/qr_gen/qrgen /app/
CMD ["/app/qrgen"]
46 changes: 38 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
Batch QR Code Generator
# Batch QR Code Generator

## Quick start
[![Tests](https://github.com/TOsmanov/qr-gen/actions/workflows/tests.yml/badge.svg)](https://github.com/TOsmanov/qr-gen/actions/workflows/tests.yml)

## QR
This application places a QR code on the background image, the data for QR codes is taken from a text file. The output will be a folder with the finished images in jpg format.
Each image will contain a qr code with an encrypted string from the data file.

## Text
## Quick start

To insert text, you need a font file in the `ttf` format.
### CLI

## Build
#### Build

Build for Windows:
```bash
env GOOS=windows GOARCH=386 go build -o qr-gen.exe
```
env GOOS=windows GOARCH=386 go build -o qr-gen.exe cli/main.go
```

Build for Linux:
```bash
env GOOS=linux GOARCH=386 go build -o qrgen_cli cli/main.go
```

#### Using

For generate images with QR-code, run:

```bash
go run ./cmd/ -file ./tests/data.txt -background ./tests/background.jpg -size 120 -h-align 50 -v-align 75 -output output
```

##### Arguments

- `-background` – The path to the background image (default "background.jpg").
- `-file` – The path to the data file for QR codes (default "data.txt").
- `-h-align` – Horizontal alignment as a percentage (default 50).
- `-output` – Folder with images (default "output").
- `-qr` – Insert qr or text (default true).
- `-size` – Size of the upper image (default 200).
- `-v-align` – Vertical alignment as a percentage (default 50).

**Text**

To insert text, you need a font file in the `ttf` format.

- `-font` – Font for text (default "./fonts/DroidSansMono.ttf").
57 changes: 57 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"flag"
"log"

qrgen "github.com/TOsmanov/qr-gen/qr-gen"
)

var (
params qrgen.Params
data string
)

func init() {
if flag.Lookup("file") == nil {
flag.StringVar(&data, "file", "data.txt", "The path to the data file for QR codes")
}
if flag.Lookup("background") == nil {
flag.StringVar(&params.BackgroundImg, "background", "background.jpg", "The path to the background image")
}
if flag.Lookup("size") == nil {
flag.IntVar(&params.Size, "size", 200, "Size of the upper image")
}
if flag.Lookup("horizontalAlign") == nil {
flag.IntVar(&params.HorizontalAlign, "h-align", 50, "Horizontal alignment as a percentage")
}
if flag.Lookup("verticalAlign") == nil {
flag.IntVar(&params.VerticalAlign, "v-align", 50, "Vertical alignment as a percentage")
}
if flag.Lookup("output") == nil {
flag.StringVar(&params.Output, "output", "output", "Folder with images")
}
if flag.Lookup("qr") == nil {
flag.BoolVar(&params.QRmode, "qr", true, "Insert qr or text")
}
if flag.Lookup("font") == nil {
flag.StringVar(&params.Font, "font", "./fonts/DroidSansMono.ttf", "Font for text")
}
}

func main() {
flag.Parse()

list, err := qrgen.PrepareData(data)
if err != nil {
log.Fatalf("Error in data preparation: %v", err)
}

params.Data = list
params.Preview = false

err = qrgen.Generation(params)
if err != nil {
log.Fatalf("Error write file: %v", err)
}
}
11 changes: 11 additions & 0 deletions config/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enviroment: "docker"

qrGen:
outputDir: "output"
siteDir: "site"
tempDir: "temp"

httpServer:
address: "qr-gen:10001"
timeout: 4s
idleTimeout: 60s
11 changes: 11 additions & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enviroment: "local"

qrGen:
outputDir: "output"
siteDir: "site"
tempDir: "temp"

httpServer:
address: "localhost:10001"
timeout: 4s
idleTimeout: 60s
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
app:
build: .
container_name: qr-gen
volumes:
- ./config/:/app/config/
- ./site/:/app/site/
ports:
- "80:10001"
environment:
CONFIG_PATH: "/app/config/docker.yaml"
33 changes: 33 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module github.com/TOsmanov/qr-gen

go 1.21

require (
github.com/fogleman/gg v1.3.0
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/render v1.0.3
github.com/go-playground/validator/v10 v10.20.0
github.com/ilyakaznacheev/cleanenv v1.5.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/stretchr/testify v1.9.0
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/image v0.16.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)
52 changes: 52 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2lOrsHHvr4=
github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ=
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw=
Loading