mirror of
https://github.com/jimeh/casecmp.git
synced 2026-02-19 10:26:40 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0eef21fd2 | |||
|
|
bbca419be6
|
||
|
f944c6e7e8
|
|||
|
6603db3e69
|
|||
|
1edbd2a7af
|
|||
|
75ddccedf3
|
|||
|
8791b80ff6
|
|||
|
e53f79024b
|
|||
|
3813304041
|
|||
| 7863eddb09 | |||
|
8ccc38c186
|
|||
|
84da611833
|
|||
|
7a152b06b2
|
|||
|
b7f4d11fc9
|
|||
|
cdaaec6b0b
|
|||
|
51717ebcd1
|
|||
|
7df597a842
|
|||
|
732c588dbc
|
|||
|
1816e93170
|
40
.github/workflows/ci.yml
vendored
40
.github/workflows/ci.yml
vendored
@@ -7,10 +7,10 @@ jobs:
|
||||
name: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.19
|
||||
- name: Install dependencies
|
||||
run: go mod download
|
||||
- name: Build binary
|
||||
@@ -21,17 +21,37 @@ jobs:
|
||||
curl --silent --retry 10 --retry-delay 1 --retry-connrefused \
|
||||
http://localhost:8080/
|
||||
|
||||
release:
|
||||
name: Release
|
||||
release-please:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
if: github.ref == 'refs/heads/main'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v2
|
||||
- uses: google-github-actions/release-please-action@v3
|
||||
id: release-please
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: Run GoReleaser
|
||||
command: manifest
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
name: Docker Login
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.19
|
||||
- if: ${{ steps.release-please.outputs.release_created }}
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
|
||||
@@ -10,18 +10,18 @@ builds:
|
||||
ldflags:
|
||||
- "-s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }}"
|
||||
goos:
|
||||
- darwin
|
||||
- freebsd
|
||||
- linux
|
||||
- windows
|
||||
- "darwin"
|
||||
- "freebsd"
|
||||
- "linux"
|
||||
- "windows"
|
||||
goarch:
|
||||
- amd64
|
||||
- 386
|
||||
- arm
|
||||
- arm64
|
||||
- "amd64"
|
||||
- "386"
|
||||
- "arm"
|
||||
- "arm64"
|
||||
goarm:
|
||||
- 6
|
||||
- 7
|
||||
- "6"
|
||||
- "7"
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
@@ -36,9 +36,71 @@ checksum:
|
||||
name_template: "checksums.txt"
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
skip: true
|
||||
|
||||
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
|
||||
|
||||
3
.release-please-manifest.json
Normal file
3
.release-please-manifest.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
".": "1.5.0"
|
||||
}
|
||||
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## [1.5.0](https://github.com/jimeh/casecmp/compare/v1.4.0...v1.5.0) (2022-11-14)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **deps:** upgrade to Go 1.19 ([75ddcce](https://github.com/jimeh/casecmp/commit/75ddccedf330497c0e04cd4b7f0679e647b8e190))
|
||||
|
||||
## [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))
|
||||
14
Dockerfile
14
Dockerfile
@@ -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 /
|
||||
|
||||
9
go.mod
9
go.mod
@@ -1,10 +1,11 @@
|
||||
module github.com/jimeh/casecmp
|
||||
|
||||
go 1.16
|
||||
go 1.19
|
||||
|
||||
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
10
go.sum
@@ -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
50
main.go
@@ -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() {
|
||||
|
||||
18
release-please-config.json
Normal file
18
release-please-config.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"bootstrap-sha": "b7f4d11fc99f9ffa85376c5757d8dd8c6341c38a",
|
||||
"last-release-sha": "b7f4d11fc99f9ffa85376c5757d8dd8c6341c38a",
|
||||
"release-type": "go",
|
||||
"bump-minor-pre-major": true,
|
||||
"bump-patch-for-minor-pre-major": true,
|
||||
"packages": {
|
||||
".": {
|
||||
"changelog-path": "CHANGELOG.md",
|
||||
"bump-minor-pre-major": false,
|
||||
"bump-patch-for-minor-pre-major": false,
|
||||
"draft": false,
|
||||
"prerelease": false,
|
||||
"extra-files": []
|
||||
}
|
||||
},
|
||||
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
||||
}
|
||||
Reference in New Issue
Block a user