mirror of
https://github.com/jimeh/casecmp.git
synced 2026-02-19 10:26:40 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
b7f4d11fc9
|
|||
|
cdaaec6b0b
|
|||
|
51717ebcd1
|
|||
|
7df597a842
|
|||
|
732c588dbc
|
|||
|
1816e93170
|
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.18
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
- name: Build binary
|
- name: Build binary
|
||||||
@@ -28,9 +28,20 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- 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
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.18
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v2
|
uses: goreleaser/goreleaser-action@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ builds:
|
|||||||
ldflags:
|
ldflags:
|
||||||
- "-s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }}"
|
- "-s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }}"
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- "darwin"
|
||||||
- freebsd
|
- "freebsd"
|
||||||
- linux
|
- "linux"
|
||||||
- windows
|
- "windows"
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- "amd64"
|
||||||
- 386
|
- "386"
|
||||||
- arm
|
- "arm"
|
||||||
- arm64
|
- "arm64"
|
||||||
goarm:
|
goarm:
|
||||||
- 6
|
- "6"
|
||||||
- 7
|
- "7"
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- format: tar.gz
|
||||||
@@ -42,3 +42,68 @@ changelog:
|
|||||||
exclude:
|
exclude:
|
||||||
- "^docs:"
|
- "^docs:"
|
||||||
- "^test:"
|
- "^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
17
CHANGELOG.md
Normal 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))
|
||||||
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
|
FROM scratch
|
||||||
COPY --from=builder /casecmp /
|
COPY ./casecmp /
|
||||||
ENV PORT 8080
|
ENV PORT 8080
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|||||||
9
go.mod
9
go.mod
@@ -1,10 +1,11 @@
|
|||||||
module github.com/jimeh/casecmp
|
module github.com/jimeh/casecmp
|
||||||
|
|
||||||
go 1.16
|
go 1.18
|
||||||
|
|
||||||
|
require gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
|
||||||
github.com/stretchr/testify v1.7.0 // 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-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
|
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
|
||||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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/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 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
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 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
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/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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
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"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
@@ -44,13 +45,26 @@ Case-insensitive string comparison, as an API. Because ¯\_(ツ)_/¯
|
|||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
curl -X POST -F "a=Foo Bar" -F "b=FOO BAR" %s://%s/
|
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)
|
name, version, scheme, r.Host, scheme, r.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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) {
|
func casecmpHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
a := r.FormValue("a")
|
a := r.FormValue("a")
|
||||||
b := r.FormValue("b")
|
b := r.FormValue("b")
|
||||||
@@ -59,22 +73,24 @@ func casecmpHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if strings.EqualFold(string(a), string(b)) {
|
if strings.EqualFold(string(a), string(b)) {
|
||||||
resp = "1"
|
resp = "1"
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(w, resp)
|
_, err := fmt.Fprint(w, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path != "/" {
|
switch r.URL.Path {
|
||||||
http.NotFound(w, r)
|
case "/":
|
||||||
return
|
if r.Method != "GET" || r.URL.RawQuery != "" {
|
||||||
}
|
casecmpHandler(w, r)
|
||||||
|
return
|
||||||
if r.Method == "GET" {
|
}
|
||||||
indexHandler(w, r)
|
indexHandler(w, r)
|
||||||
} else {
|
case "/about":
|
||||||
casecmpHandler(w, r)
|
aboutHandler(w, r)
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +106,6 @@ func printVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
http.HandleFunc("/", rootHandler)
|
|
||||||
|
|
||||||
if *portFlag == "" {
|
if *portFlag == "" {
|
||||||
envPort := os.Getenv("PORT")
|
envPort := os.Getenv("PORT")
|
||||||
if envPort != "" {
|
if envPort != "" {
|
||||||
@@ -107,7 +121,15 @@ func startServer() {
|
|||||||
|
|
||||||
address := *bindFlag + ":" + *portFlag
|
address := *bindFlag + ":" + *portFlag
|
||||||
fmt.Printf("Listening on %s\n", address)
|
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() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user