4 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
5 changed files with 59 additions and 24 deletions

View File

@@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18
- name: Install dependencies
run: go mod download
- name: Build binary
@@ -28,8 +28,11 @@ jobs:
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:
@@ -38,7 +41,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:

View File

@@ -2,6 +2,13 @@
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)

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() {