mirror of
https://github.com/jimeh/casecmp.git
synced 2026-02-19 10:26:40 +00:00
feat!: remove external dependencies
Remove the kingpin external dependency, and instead just use Go's stdlib flag package. BREAKING CHANGE: Long versions of command line flags are no longer supported.
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
|||||||
run: make
|
run: make
|
||||||
- name: Run and make request
|
- name: Run and make request
|
||||||
run: |
|
run: |
|
||||||
./bin/casecmp --port=8080 &
|
./bin/casecmp -p 8080 &
|
||||||
curl --silent --retry 10 --retry-delay 1 --retry-connrefused \
|
curl --silent --retry 10 --retry-delay 1 --retry-connrefused \
|
||||||
http://localhost:8080/
|
http://localhost:8080/
|
||||||
|
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -4,11 +4,10 @@ VERSION ?= $(shell cat VERSION)
|
|||||||
SOURCES = $(shell find . -name '*.go' -o -name 'Makefile')
|
SOURCES = $(shell find . -name '*.go' -o -name 'Makefile')
|
||||||
|
|
||||||
$(BINARY): $(SOURCES)
|
$(BINARY): $(SOURCES)
|
||||||
CGO_ENABLED=0 go build -a -o ${BINARY} -ldflags \ "\
|
CGO_ENABLED=0 go build -o ${BINARY} -ldflags \ "\
|
||||||
-s -w \
|
-s -w \
|
||||||
-X main.version=${VERSION} \
|
-X main.version=${VERSION} \
|
||||||
-X main.commit=$(shell git show --format="%h" --no-patch) \
|
-X main.commit=$(shell git show --format="%h" --no-patch)"
|
||||||
-X main.date=$(shell date +%Y-%m-%dT%T%z)"
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: $(BINARY)
|
build: $(BINARY)
|
||||||
|
|||||||
8
go.mod
8
go.mod
@@ -1,11 +1,3 @@
|
|||||||
module github.com/jimeh/casecmp
|
module github.com/jimeh/casecmp
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
|
||||||
|
|
||||||
require (
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|||||||
18
go.sum
18
go.sum
@@ -1,18 +0,0 @@
|
|||||||
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=
|
|
||||||
|
|||||||
58
main.go
58
main.go
@@ -2,35 +2,35 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
version = "dev"
|
||||||
|
commit = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
name = "casecmp"
|
name = "casecmp"
|
||||||
version = "dev"
|
defaultPort = 8080
|
||||||
commit = "unknown"
|
defaultBind = "0.0.0.0"
|
||||||
date = "unknown"
|
|
||||||
defaultPort = "8080"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Argument parsing setup.
|
// Argument parsing setup.
|
||||||
var (
|
var (
|
||||||
portFlag = kingpin.Flag("port", "Port to listen to.").Short('p').
|
portFlag = flag.Int("p", defaultPort, "Port to listen on")
|
||||||
Default("").String()
|
bindFlag = flag.String("b", defaultBind, "Bind address")
|
||||||
bindFlag = kingpin.Flag("bind", "Bind address.").Short('b').
|
forceHTTPSFlag = flag.Bool(
|
||||||
Default("0.0.0.0").String()
|
"f", false, "Use https:// in example curl commands",
|
||||||
forceHTTPSFlag = kingpin.Flag(
|
)
|
||||||
"force-https", "Use https:// in example curl commands",
|
versionFlag = flag.Bool("v", false, "Print version info")
|
||||||
).Bool()
|
|
||||||
versionFlag = kingpin.Flag("version", "Print version info.").
|
|
||||||
Short('v').Bool()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -105,13 +105,16 @@ func printVersion() {
|
|||||||
fmt.Println(buffer.String())
|
fmt.Println(buffer.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
func startServer() error {
|
||||||
if *portFlag == "" {
|
if *portFlag == defaultPort {
|
||||||
envPort := os.Getenv("PORT")
|
envPort := os.Getenv("PORT")
|
||||||
if envPort != "" {
|
if envPort != "" {
|
||||||
*portFlag = envPort
|
v, err := strconv.Atoi(envPort)
|
||||||
} else {
|
if err != nil {
|
||||||
*portFlag = defaultPort
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*portFlag = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +122,9 @@ func startServer() {
|
|||||||
*forceHTTPSFlag = true
|
*forceHTTPSFlag = true
|
||||||
}
|
}
|
||||||
|
|
||||||
address := *bindFlag + ":" + *portFlag
|
address := fmt.Sprintf("%s:%d", *bindFlag, *portFlag)
|
||||||
fmt.Printf("Listening on %s\n", address)
|
fmt.Printf("Listening on %s\n", address)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
WriteTimeout: 5 * time.Second,
|
WriteTimeout: 5 * time.Second,
|
||||||
@@ -129,15 +133,19 @@ func startServer() {
|
|||||||
Addr: address,
|
Addr: address,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Fatal(srv.ListenAndServe())
|
return srv.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
kingpin.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *versionFlag {
|
if *versionFlag {
|
||||||
printVersion()
|
printVersion()
|
||||||
} else {
|
return
|
||||||
startServer()
|
}
|
||||||
|
|
||||||
|
err := startServer()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user