Initial commit

This commit is contained in:
Marcus Noble 2020-05-08 14:30:50 +01:00
commit 175354acd3
8 changed files with 146 additions and 0 deletions

18
.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
/vendor/
/Godeps/
qr
.vscode

16
Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM golang:alpine AS builder
RUN apk update && apk add --no-cache git && adduser -D -g '' gopher && apk add -U --no-cache ca-certificates
WORKDIR /app/
ADD go.mod go.sum ./
RUN go mod download
ADD . .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o qr main.go
FROM scratch
WORKDIR /app/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /app/qr /app/qr
USER gopher
ENTRYPOINT ["/app/qr"]

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2020 Marcus Noble
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

61
Makefile Normal file
View File

@ -0,0 +1,61 @@
.DEFAULT_GOAL := default
IMAGE ?= docker.cluster.fun/averagemarcus/qr:latest
.PHONY: test # Run all tests, linting and format checks
test: lint check-format run-tests
.PHONY: lint # Perform lint checks against code
lint:
@go vet && golint -set_exit_status ./...
.PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found
check-format:
@gofmt -e -l .
.PHONY: format # Performs automatic format fixes on all code
format:
@gofmt -s -w .
.PHONY: run-tests # Runs all tests
run-tests:
@go test
.PHONY: fetch-deps # Fetch all project dependencies
fetch-deps:
@go mod tidy
.PHONY: build # Build the project
build: lint check-format fetch-deps
@go build -o qr main.go
.PHONY: docker-build # Build the docker image
docker-build:
@docker build -t $(IMAGE) .
.PHONY: docker-publish # Push the docker image to the remote registry
docker-publish:
@docker push $(IMAGE)
.PHONY: run # Run the application
run:
@go run main.go
.PHONY: ci # Perform CI specific tasks to perform on a pull request
ci:
@echo "⚠️ 'ci' unimplemented"
.PHONY: release # Release the latest version of the application
release:
@echo "⚠️ 'release' unimplemented"
.PHONY: help # Show this list of commands
help:
@echo "${REPO_NAME}"
@echo "Usage: make [target]"
@echo ""
@echo "target description" | expand -t20
@echo "-----------------------------------"
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \2/' | expand -t20
default: test build

1
README.md Normal file
View File

@ -0,0 +1 @@
# qr

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module qr
go 1.13
require github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 h1:RYiqpb2ii2Z6J4x0wxK46kvPBbFuZcdhS+CIztmYgZs=
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=

21
main.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
qrcode "github.com/skip2/go-qrcode"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
website := req.URL.Query().Get("website")
if website != "" {
png, _ := qrcode.Encode(website, qrcode.Medium, 80)
w.Write(png)
return
}
w.WriteHeader(400)
})
fmt.Println(http.ListenAndServe(":8080", nil))
}