14 Commits

Author SHA1 Message Date
b7f4d11fc9 chore(release): 1.4.0 2022-05-24 17:40:24 +01:00
cdaaec6b0b feat: compare on GET requests with non-empty query string
Also add a /about page so there's a non-root page that does not return
404.
2022-05-24 17:39:12 +01:00
51717ebcd1 chore(ci): fix release job 2022-05-24 17:38:49 +01:00
7df597a842 chore(go): upgrade to Go 1.18 2022-05-24 17:38:24 +01:00
732c588dbc chore(release): 1.3.0 2022-02-13 04:13:41 +00:00
1816e93170 feat(release): setup for publishing docker images to ghcr 2022-02-13 04:11:29 +00:00
29902b2e8e chore(release): 1.2.3 2021-04-14 20:43:46 +01:00
36e0863cc3 fix(release): add missing GITHUB_TOKEN env var 2021-04-14 20:43:18 +01:00
5471ff95a7 chore(release): 1.2.2 2021-04-14 20:39:57 +01:00
4c89c92f75 build(release): tweak goreleaser config 2021-04-14 20:38:46 +01:00
d19eed020c Merge pull request #3 from jimeh/github-actions
ci(github): switch from CircleCI to GitHub Actions
2021-04-14 20:34:57 +01:00
aef3e832f5 ci(github): switch from CircleCI to GitHub Actions 2021-04-14 20:32:50 +01:00
3bae8acc62 chore(release): 1.2.1 2021-04-14 20:13:01 +01:00
eaf738c49f fix(release): fix goreleaser setup 2021-04-14 20:12:23 +01:00
10 changed files with 224 additions and 132 deletions

View File

@@ -1,65 +0,0 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.16
working_directory: /go/src/github.com/jimeh/casecmp
steps:
- checkout
- run:
name: Install dependencies
command: go mod download
- run:
name: Build binary
command: make
- run:
name: Start service
command: ./bin/casecmp --port=8080
background: true
- run:
name: Validate service is working
command: |
curl --retry 10 --retry-delay 1 --retry-connrefused \
http://localhost:8080/
release:
docker:
- image: circleci/golang:1.16
working_directory: /go/src/github.com/jimeh/casecmp
steps:
- checkout
- run:
name: Install tools
command: |
go get github.com/goreleaser/goreleaser
- run:
name: Install dependencies
command: go mod download
- run:
name: Run goreleaser
command: goreleaser
workflows:
version: 2
build:
jobs:
- build:
filters:
branches:
only: /.*/
tags:
ignore: /^v[0-9]+(\.[0-9]+)*/
build-and-release:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*/
- release:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*/

51
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,51 @@
---
name: CI
on: [push]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Install dependencies
run: go mod download
- name: Build binary
run: make
- name: Run and make request
run: |
./bin/casecmp --port=8080 &
curl --silent --retry 10 --retry-delay 1 --retry-connrefused \
http://localhost:8080/
release:
name: Release
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
bin/*
dist/*
releases/*
dist/

View File

@@ -1,34 +1,109 @@
project_name: casecmp
builds:
- main: main.go
binary: casecmp
flags: -a
env:
- CGO_ENABLED=0
goos:
- darwin
- freebsd
- linux
- windows
goarch:
- amd64
- 386
- arm
goarm:
- 6
- 7
archive:
name_template: '{{ .ProjectName }}-{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm
}}v{{ .Arm }}{{ end }}'
format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
before:
hooks:
- make clean
git:
short_hash: true
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
mod_timestamp: "{{ .CommitTimestamp }}"
flags:
- -trimpath
ldflags:
- "-s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }}"
goos:
- "darwin"
- "freebsd"
- "linux"
- "windows"
goarch:
- "amd64"
- "386"
- "arm"
- "arm64"
goarm:
- "6"
- "7"
archives:
- format: tar.gz
name_template: |-
{{ .ProjectName }}-{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
snapshot:
name_template: snapshot-{{.Commit}}
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
dockers:
- image_templates:
- "ghcr.io/jimeh/casecmp:{{ .Version }}-amd64"
- "ghcr.io/jimeh/casecmp:latest-amd64"
dockerfile: Dockerfile
use: buildx
goos: linux
goarch: amd64
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- "ghcr.io/jimeh/casecmp:{{ .Version }}-386"
- "ghcr.io/jimeh/casecmp:latest-386"
dockerfile: Dockerfile
use: buildx
goos: linux
goarch: "386"
build_flag_templates:
- "--platform=linux/386"
- image_templates:
- "ghcr.io/jimeh/casecmp:{{ .Version }}-arm64"
- "ghcr.io/jimeh/casecmp:latest-arm64"
use: buildx
goos: linux
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm64"
- image_templates:
- "ghcr.io/jimeh/casecmp:{{ .Version }}-armv6"
- "ghcr.io/jimeh/casecmp:latest-armv6"
use: buildx
goos: linux
goarch: arm
goarm: "6"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm/v6"
- image_templates:
- "ghcr.io/jimeh/casecmp:{{ .Version }}-armv7"
- "ghcr.io/jimeh/casecmp:latest-armv7"
use: buildx
goos: linux
goarch: arm
goarm: "7"
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm/v7"
docker_manifests:
- name_template: ghcr.io/jimeh/casecmp:{{ .Version }}
image_templates:
- ghcr.io/jimeh/casecmp:{{ .Version }}-amd64
- ghcr.io/jimeh/casecmp:{{ .Version }}-386
- ghcr.io/jimeh/casecmp:{{ .Version }}-arm64
- ghcr.io/jimeh/casecmp:{{ .Version }}-armv6
- ghcr.io/jimeh/casecmp:{{ .Version }}-armv7
- name_template: ghcr.io/jimeh/casecmp:latest
image_templates:
- ghcr.io/jimeh/casecmp:latest-amd64
- ghcr.io/jimeh/casecmp:latest-386
- ghcr.io/jimeh/casecmp:latest-arm64
- ghcr.io/jimeh/casecmp:latest-armv6
- ghcr.io/jimeh/casecmp:latest-armv7

17
CHANGELOG.md Normal file
View File

@@ -0,0 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [1.4.0](https://github.com/jimeh/casecmp/compare/v1.3.0...v1.4.0) (2022-05-24)
### Features
* compare on GET requests with non-empty query string ([cdaaec6](https://github.com/jimeh/casecmp/commit/cdaaec6b0b763141476562047578844e6105ec7a))
## [1.3.0](https://github.com/jimeh/casecmp/compare/v1.2.3...v1.3.0) (2022-02-13)
### Features
* **release:** setup for publishing docker images to ghcr ([1816e93](https://github.com/jimeh/casecmp/commit/1816e93170bb725f8da073b91070a981dd039fad))

View File

@@ -1,17 +1,5 @@
FROM golang:1.16-alpine as builder
RUN apk add --no-cache \
git
WORKDIR /app
COPY . /app
RUN env CGO_ENABLED=0 \
go build -a -o /casecmp -ldflags "-s -w \
-X main.version=$(cat VERSION) \
-X main.commit=$(git show --format='%h' --no-patch) \
-X main.date=$(date +%Y-%m-%dT%T%z)"
FROM scratch
COPY --from=builder /casecmp /
COPY ./casecmp /
ENV PORT 8080
EXPOSE 8080
WORKDIR /

View File

@@ -1 +1 @@
1.2.0
1.2.3

9
go.mod
View File

@@ -1,10 +1,11 @@
module github.com/jimeh/casecmp
go 1.16
go 1.18
require gopkg.in/alecthomas/kingpin.v2 v2.2.6
require (
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/stretchr/testify v1.7.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

10
go.sum
View File

@@ -1,16 +1,18 @@
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

50
main.go
View File

@@ -7,6 +7,7 @@ import (
"net/http"
"os"
"strings"
"time"
"gopkg.in/alecthomas/kingpin.v2"
)
@@ -44,13 +45,26 @@ Case-insensitive string comparison, as an API. Because ¯\_(ツ)_/¯
Example usage:
curl -X POST -F "a=Foo Bar" -F "b=FOO BAR" %s://%s/
curl -X POST "%s://%s/?a=Foo+Bar&b=FOO+BAR"`,
curl -X GET "%s://%s/?a=Foo+Bar&b=FOO+BAR"
`,
name, version, scheme, r.Host, scheme, r.Host)
if err != nil {
log.Fatal(err)
}
}
func aboutHandler(w http.ResponseWriter, _ *http.Request) {
_, err := fmt.Fprintf(w,
`%s %s
https://github.com/jimeh/casecmp
`,
name, version)
if err != nil {
log.Fatal(err)
}
}
func casecmpHandler(w http.ResponseWriter, r *http.Request) {
a := r.FormValue("a")
b := r.FormValue("b")
@@ -59,22 +73,24 @@ func casecmpHandler(w http.ResponseWriter, r *http.Request) {
if strings.EqualFold(string(a), string(b)) {
resp = "1"
}
_, err := fmt.Fprintf(w, resp)
_, err := fmt.Fprint(w, resp)
if err != nil {
log.Fatal(err)
}
}
func rootHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
if r.Method == "GET" {
func handler(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
if r.Method != "GET" || r.URL.RawQuery != "" {
casecmpHandler(w, r)
return
}
indexHandler(w, r)
} else {
casecmpHandler(w, r)
case "/about":
aboutHandler(w, r)
default:
http.NotFound(w, r)
}
}
@@ -90,8 +106,6 @@ func printVersion() {
}
func startServer() {
http.HandleFunc("/", rootHandler)
if *portFlag == "" {
envPort := os.Getenv("PORT")
if envPort != "" {
@@ -107,7 +121,15 @@ func startServer() {
address := *bindFlag + ":" + *portFlag
fmt.Printf("Listening on %s\n", address)
log.Fatal(http.ListenAndServe(address, nil))
srv := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 30 * time.Second,
Handler: http.HandlerFunc(handler),
Addr: address,
}
log.Fatal(srv.ListenAndServe())
}
func main() {