mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-06 20:19:26 +00:00
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
0090b794ee | |||
93f561d6ef | |||
9da6d2fec5 | |||
8e3d731719
|
|||
d5b244dc5f
|
|||
d767afd658
|
|||
f4fd79737e
|
|||
2ab6b29ed5
|
|||
55e6cd4816
|
|||
a490d5f10e
|
|||
994a12da5a | |||
91deff4a14 | |||
81c3a4fbb0 | |||
5b85eef7eb | |||
c54cf5a456
|
|||
7dfa0a2e6d
|
|||
68ef680439 | |||
bd42f712ea | |||
0b31633309
|
|||
b5fa3be506
|
3
.github/workflows/codeql-analysis.yml
vendored
3
.github/workflows/codeql-analysis.yml
vendored
@ -29,9 +29,6 @@ jobs:
|
|||||||
contents: read
|
contents: read
|
||||||
security-events: write
|
security-events: write
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
3
.github/workflows/main.yml
vendored
3
.github/workflows/main.yml
vendored
@ -18,10 +18,9 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: install go
|
- name: install go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
cache: true
|
|
||||||
|
|
||||||
- name: ${{ matrix.make }}
|
- name: ${{ matrix.make }}
|
||||||
run: make ${{ matrix.make }}
|
run: make ${{ matrix.make }}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.20-alpine as builder
|
FROM golang:1.21-alpine as builder
|
||||||
|
|
||||||
ARG ARG_VERSION
|
ARG ARG_VERSION
|
||||||
ENV VERSION $ARG_VERSION
|
ENV VERSION $ARG_VERSION
|
||||||
@ -7,7 +7,8 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN apk add make git && make build VERSION=$VERSION
|
RUN apk add make git upx && make build VERSION=$VERSION \
|
||||||
|
&& upx --best --lzma whatismyip
|
||||||
|
|
||||||
# Build final image
|
# Build final image
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
@ -138,7 +138,7 @@ Download the latest version from https://github.com/dcarrillo/whatismyip/release
|
|||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
An ultra-light (~12MB) image is available at [docker hub](https://hub.docker.com/r/dcarrillo/whatismyip).
|
An ultra-light (~4MB) image is available on [docker hub](https://hub.docker.com/r/dcarrillo/whatismyip). Since version `2.1.2`, the binary is compressed using [upx](https://github.com/upx/upx).
|
||||||
|
|
||||||
### Run a container locally using test databases
|
### Run a container locally using test databases
|
||||||
|
|
||||||
|
109
go.mod
109
go.mod
@ -1,77 +1,88 @@
|
|||||||
module github.com/dcarrillo/whatismyip
|
module github.com/dcarrillo/whatismyip
|
||||||
|
|
||||||
go 1.20
|
go 1.21.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-contrib/secure v0.0.1
|
github.com/gin-contrib/secure v0.0.1
|
||||||
github.com/gin-gonic/gin v1.9.0
|
github.com/gin-gonic/gin v1.9.1
|
||||||
github.com/oschwald/maxminddb-golang v1.10.0
|
github.com/oschwald/maxminddb-golang v1.12.0
|
||||||
github.com/quic-go/quic-go v0.33.0
|
github.com/quic-go/quic-go v0.39.3
|
||||||
github.com/stretchr/testify v1.8.2
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/testcontainers/testcontainers-go v0.13.0
|
github.com/testcontainers/testcontainers-go v0.26.0
|
||||||
golang.org/x/net v0.8.0
|
golang.org/x/net v0.17.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
dario.cat/mergo v1.0.0 // indirect
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||||
github.com/Microsoft/go-winio v0.5.2 // indirect
|
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||||
github.com/Microsoft/hcsshim v0.9.6 // indirect
|
github.com/Microsoft/hcsshim v0.11.1 // indirect
|
||||||
github.com/bytedance/sonic v1.8.5 // indirect
|
github.com/bytedance/sonic v1.10.2 // indirect
|
||||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||||
github.com/containerd/cgroups v1.0.4 // indirect
|
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
||||||
github.com/containerd/containerd v1.6.18 // indirect
|
github.com/containerd/containerd v1.7.7 // indirect
|
||||||
|
github.com/containerd/log v0.1.0 // indirect
|
||||||
|
github.com/cpuguy83/dockercfg v0.3.1 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
github.com/docker/distribution v2.8.2+incompatible // indirect
|
||||||
github.com/docker/docker v20.10.17+incompatible // indirect
|
github.com/docker/docker v24.0.7+incompatible // indirect
|
||||||
github.com/docker/go-connections v0.4.0 // indirect
|
github.com/docker/go-connections v0.4.0 // indirect
|
||||||
github.com/docker/go-units v0.4.0 // indirect
|
github.com/docker/go-units v0.5.0 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/go-playground/validator/v10 v10.11.2 // indirect
|
github.com/go-playground/validator/v10 v10.15.5 // indirect
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
||||||
github.com/goccy/go-json v0.10.1 // indirect
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
|
||||||
github.com/golang/mock v1.6.0 // indirect
|
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect
|
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.1 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
github.com/klauspost/compress v1.16.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.2 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
github.com/moby/sys/mount v0.3.3 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
github.com/moby/sys/mountinfo v0.6.2 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/moby/patternmatcher v0.6.0 // indirect
|
||||||
|
github.com/moby/sys/sequential v0.5.0 // indirect
|
||||||
|
github.com/moby/term v0.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/morikuni/aec v1.0.0 // indirect
|
github.com/morikuni/aec v1.0.0 // indirect
|
||||||
github.com/onsi/ginkgo/v2 v2.9.1 // indirect
|
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
|
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
|
||||||
github.com/opencontainers/runc v1.1.3 // indirect
|
github.com/opencontainers/runc v1.1.5 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
github.com/quic-go/qpack v0.4.0 // indirect
|
github.com/quic-go/qpack v0.4.0 // indirect
|
||||||
github.com/quic-go/qtls-go1-19 v0.3.0 // indirect
|
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
|
||||||
github.com/quic-go/qtls-go1-20 v0.2.0 // indirect
|
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
go.opencensus.io v0.23.0 // indirect
|
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||||
golang.org/x/arch v0.3.0 // indirect
|
go.uber.org/mock v0.3.0 // indirect
|
||||||
golang.org/x/crypto v0.7.0 // indirect
|
golang.org/x/arch v0.5.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect
|
golang.org/x/crypto v0.17.0 // indirect
|
||||||
golang.org/x/mod v0.9.0 // indirect
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||||
golang.org/x/sys v0.6.0 // indirect
|
golang.org/x/mod v0.13.0 // indirect
|
||||||
golang.org/x/text v0.8.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
golang.org/x/tools v0.7.0 // indirect
|
golang.org/x/text v0.14.0 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20220810155839-1856144b1d9c // indirect
|
golang.org/x/tools v0.14.0 // indirect
|
||||||
google.golang.org/grpc v1.48.0 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
|
||||||
google.golang.org/protobuf v1.30.0 // indirect
|
google.golang.org/grpc v1.57.1 // indirect
|
||||||
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
@ -119,7 +119,7 @@ func TestContainerIntegration(t *testing.T) {
|
|||||||
resp, _ = client.Do(req)
|
resp, _ = client.Do(req)
|
||||||
body, err = io.ReadAll(resp.Body)
|
body, err = io.ReadAll(resp.Body)
|
||||||
if strings.Contains(tt.url, "https://") {
|
if strings.Contains(tt.url, "https://") {
|
||||||
assert.Equal(t, `h3=":8001"; ma=2592000,h3-29=":8001"; ma=2592000`, resp.Header.Get("Alt-Svc"))
|
assert.Equal(t, `h3=":8001"; ma=2592000`, resp.Header.Get("Alt-Svc"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -44,10 +44,10 @@ func (q *QuicServer) Start() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Printf("Stopping QUIC server...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QuicServer) Stop() {
|
func (q *QuicServer) Stop() {
|
||||||
|
log.Printf("Stopping QUIC server...")
|
||||||
if err := q.server.Close(); err != nil {
|
if err := q.server.Close(); err != nil {
|
||||||
log.Printf("QUIC server forced to shutdown")
|
log.Printf("QUIC server forced to shutdown")
|
||||||
}
|
}
|
||||||
|
@ -46,56 +46,51 @@ func Setup(ctx context.Context, handler http.Handler) *Factory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Factory) Run() {
|
func (f *Factory) Run() {
|
||||||
w.start()
|
f.start()
|
||||||
log.Printf("Starting server handler...")
|
|
||||||
w.Watcher()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Factory) Watcher() {
|
|
||||||
signalChan := make(chan os.Signal, 3)
|
signalChan := make(chan os.Signal, 3)
|
||||||
signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
|
||||||
var s os.Signal
|
var s os.Signal
|
||||||
|
|
||||||
for {
|
for {
|
||||||
s = <-signalChan
|
s = <-signalChan
|
||||||
|
|
||||||
if s == syscall.SIGHUP {
|
if s == syscall.SIGHUP {
|
||||||
w.stop()
|
f.stop()
|
||||||
models.CloseDBs()
|
models.CloseDBs()
|
||||||
models.Setup(setting.App.GeodbPath.City, setting.App.GeodbPath.ASN)
|
models.Setup(setting.App.GeodbPath.City, setting.App.GeodbPath.ASN)
|
||||||
w.start()
|
f.start()
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Shutting down...")
|
log.Printf("Shutting down...")
|
||||||
w.stop()
|
f.stop()
|
||||||
models.CloseDBs()
|
models.CloseDBs()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Factory) start() {
|
func (f *Factory) start() {
|
||||||
if w.tcpServer != nil {
|
if f.tcpServer != nil {
|
||||||
w.tcpServer.Start()
|
f.tcpServer.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.tlsServer != nil {
|
if f.tlsServer != nil {
|
||||||
w.tlsServer.Start()
|
f.tlsServer.Start()
|
||||||
if w.quicServer != nil {
|
if f.quicServer != nil {
|
||||||
w.quicServer.Start()
|
f.quicServer.Start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Factory) stop() {
|
func (f *Factory) stop() {
|
||||||
if w.tcpServer != nil {
|
if f.tcpServer != nil {
|
||||||
w.tcpServer.Stop()
|
f.tcpServer.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.tlsServer != nil {
|
if f.tlsServer != nil {
|
||||||
if w.quicServer != nil {
|
if f.quicServer != nil {
|
||||||
w.quicServer.Stop()
|
f.quicServer.Stop()
|
||||||
}
|
}
|
||||||
w.tlsServer.Stop()
|
f.tlsServer.Stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,10 @@ func (t *TCPServer) Start() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Printf("Stopping TCP server...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TCPServer) Stop() {
|
func (t *TCPServer) Stop() {
|
||||||
|
log.Printf("Stopping TCP server...")
|
||||||
if err := t.server.Shutdown(t.ctx); err != nil {
|
if err := t.server.Shutdown(t.ctx); err != nil {
|
||||||
log.Printf("TCP server forced to shutdown: %s", err)
|
log.Printf("TCP server forced to shutdown: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ func (t *TLSServer) Start() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Printf("Stopping TLS server...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TLSServer) Stop() {
|
func (t *TLSServer) Stop() {
|
||||||
|
log.Printf("Stopping TLS server...")
|
||||||
if err := t.server.Shutdown(t.ctx); err != nil {
|
if err := t.server.Shutdown(t.ctx); err != nil {
|
||||||
log.Printf("TLS server forced to shutdown: %s", err)
|
log.Printf("TLS server forced to shutdown: %s", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user