Skip to content

Commit de1d9e0

Browse files
authored
Package upgrades and more (#7)
[minor] introduced probe responder [patch] added APM for Postgres driver [patch] upgraded all dependencies [patch] introduced graceful shutdown [patch] split initialisations and shutdown to different files for reducing clutter in main.go
1 parent b0bb3ed commit de1d9e0

23 files changed

Lines changed: 458 additions & 336 deletions

README.md

Lines changed: 29 additions & 23 deletions
Large diffs are not rendered by default.

cmd/server/grpc/grpc.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package grpc
22

3-
import "github.com/naughtygopher/goapp/internal/api"
3+
import (
4+
"context"
5+
6+
"github.com/naughtygopher/goapp/internal/api"
7+
)
48

59
type GRPC struct {
610
apis api.Server
711
}
812

13+
func (gr *GRPC) Shutdown(ctx context.Context) error {
14+
_ = ctx
15+
return nil
16+
}
17+
918
func New(apis api.Server) *GRPC {
1019
return &GRPC{
1120
apis: apis,

cmd/server/http/handlers.go

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"net/http"
88
"runtime/debug"
99

10-
"github.com/bnkamalesh/errors"
11-
"github.com/bnkamalesh/webgo/v7"
10+
"github.com/naughtygopher/errors"
11+
"github.com/naughtygopher/webgo/v7"
1212

1313
"github.com/naughtygopher/goapp/internal/api"
1414
"github.com/naughtygopher/goapp/internal/pkg/logger"
@@ -29,13 +29,6 @@ func (h *Handlers) routes() []*webgo.Route {
2929
Handlers: []http.HandlerFunc{errWrapper(h.HelloWorld)},
3030
TrailingSlash: true,
3131
},
32-
{
33-
Name: "health",
34-
Pattern: "/-/health",
35-
Method: http.MethodGet,
36-
Handlers: []http.HandlerFunc{errWrapper(h.Health)},
37-
TrailingSlash: true,
38-
},
3932
{
4033
Name: "create-user",
4134
Pattern: "/users",
@@ -53,18 +46,6 @@ func (h *Handlers) routes() []*webgo.Route {
5346
}
5447
}
5548

56-
// Health is the HTTP handler to return the status of the app including the version, and other details
57-
// This handler uses webgo to respond to the http request
58-
func (h *Handlers) Health(w http.ResponseWriter, r *http.Request) error {
59-
out, err := h.apis.ServerHealth()
60-
if err != nil {
61-
return err
62-
}
63-
webgo.R200(w, out)
64-
return nil
65-
}
66-
67-
// HelloWorld is a helloworld HTTP handler
6849
func (h *Handlers) HelloWorld(w http.ResponseWriter, r *http.Request) error {
6950
contentType := r.Header.Get("Content-Type")
7051
switch contentType {

cmd/server/http/handlers_usernotes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"encoding/json"
55
"net/http"
66

7-
"github.com/bnkamalesh/errors"
7+
"github.com/naughtygopher/errors"
88
"github.com/naughtygopher/goapp/internal/usernotes"
9-
"github.com/bnkamalesh/webgo/v7"
9+
"github.com/naughtygopher/webgo/v7"
1010
)
1111

1212
func (h *Handlers) CreateUserNote(w http.ResponseWriter, r *http.Request) error {

cmd/server/http/handlers_users.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"encoding/json"
55
"net/http"
66

7-
"github.com/bnkamalesh/errors"
8-
"github.com/bnkamalesh/webgo/v7"
7+
"github.com/naughtygopher/errors"
8+
"github.com/naughtygopher/webgo/v7"
99

1010
"github.com/naughtygopher/goapp/internal/users"
1111
)

cmd/server/http/http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/bnkamalesh/errors"
11+
"github.com/naughtygopher/errors"
1212
"github.com/naughtygopher/goapp/internal/api"
1313
"github.com/naughtygopher/goapp/internal/pkg/apm"
14-
"github.com/bnkamalesh/webgo/v7"
15-
"github.com/bnkamalesh/webgo/v7/middleware/accesslog"
14+
"github.com/naughtygopher/webgo/v7"
15+
"github.com/naughtygopher/webgo/v7/middleware/accesslog"
1616
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1717
)
1818

docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM golang:1.22 AS builder
1+
FROM golang:1.23 AS builder
22

33
COPY ../ /app
44
WORKDIR /app
55
RUN ls
66
# Toggle CGO on your app requirement
7-
RUN CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' -o /app/appbin main.go
7+
RUN CGO_ENABLED=0 go build -ldflags '-s -w -extldflags "-static"' -o /app/appbin *.go
88
# Use below if using vendor
99
# RUN CGO_ENABLED=0 go build -mod=vendor -ldflags '-extldflags "-static"' -o /app/appbin *.go
1010

@@ -23,7 +23,7 @@ RUN adduser --home "/appuser" --disabled-password appuser \
2323
--gecos "appuser,-,-,-"
2424
USER appuser
2525

26-
COPY --from=builder /app/internal/server/http/web /home/appuser/app/web
26+
COPY --from=builder /app/cmd/server/http/web /home/appuser/app/web
2727
COPY --from=builder /app/appbin /home/appuser/app
2828

2929
ENV TEMPLATES_BASEPATH=/home/appuser/app/web/templates

docker/docker-compose.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
version: "3.9"
21
services:
3-
redis:
4-
image: "redis:7"
5-
networks:
6-
- goapp_network
7-
82
postgres:
9-
image: "postgres:16"
3+
image: "postgres:17"
104
environment:
115
POSTGRES_PASSWORD: gauserpassword
126
POSTGRES_USER: gauser
@@ -17,9 +11,9 @@ services:
1711
- goapp_network
1812

1913
goapp:
20-
image: golang:1.22
14+
image: golang:1.23
2115
volumes:
22-
- ${PWD}:/app
16+
- ${PWD}/../:/app
2317
working_dir: /app
2418
tty: true
2519
environment:
@@ -29,11 +23,11 @@ services:
2923
POSTGRES_STORENAME: "goapp"
3024
POSTGRES_USERNAME: "gauser"
3125
POSTGRES_PASSWORD: "gauserpassword"
32-
command: go run main.go
26+
command: ["go", "run", "inits.go", "shutdown.go", "main.go"]
3327
ports:
3428
- "8080:8080"
29+
- "2000:2000"
3530
depends_on:
36-
- redis
3731
- postgres
3832
networks:
3933
- goapp_network

go.mod

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
module github.com/naughtygopher/goapp
22

3-
go 1.22
3+
go 1.22.0
44

55
require (
66
github.com/Masterminds/squirrel v1.5.4
7-
github.com/bnkamalesh/errors v0.11.1
8-
github.com/bnkamalesh/webgo/v7 v7.0.1
7+
github.com/exaring/otelpgx v0.8.0
98
github.com/google/uuid v1.6.0
10-
github.com/jackc/pgx/v5 v5.7.1
11-
github.com/prometheus/client_golang v1.20.4
12-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0
13-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0
14-
go.opentelemetry.io/contrib/propagators/b3 v1.30.0
15-
go.opentelemetry.io/otel v1.30.0
16-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0
17-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0
18-
go.opentelemetry.io/otel/exporters/prometheus v0.52.0
19-
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.30.0
20-
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0
21-
go.opentelemetry.io/otel/metric v1.30.0
22-
go.opentelemetry.io/otel/sdk v1.30.0
23-
go.opentelemetry.io/otel/sdk/metric v1.30.0
24-
go.opentelemetry.io/otel/trace v1.30.0
25-
golang.org/x/sync v0.8.0
26-
google.golang.org/grpc v1.67.1
9+
github.com/jackc/pgx/v5 v5.7.2
10+
github.com/naughtygopher/errors v1.0.1
11+
github.com/naughtygopher/proberesponder v0.6.3
12+
github.com/naughtygopher/webgo/v7 v7.0.5
13+
github.com/prometheus/client_golang v1.20.5
14+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0
15+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0
16+
go.opentelemetry.io/contrib/propagators/b3 v1.34.0
17+
go.opentelemetry.io/otel v1.34.0
18+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0
19+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0
20+
go.opentelemetry.io/otel/exporters/prometheus v0.56.0
21+
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.34.0
22+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.34.0
23+
go.opentelemetry.io/otel/metric v1.34.0
24+
go.opentelemetry.io/otel/sdk v1.34.0
25+
go.opentelemetry.io/otel/sdk/metric v1.34.0
26+
go.opentelemetry.io/otel/trace v1.34.0
27+
golang.org/x/sync v0.10.0
28+
google.golang.org/grpc v1.70.0
2729
)
2830

2931
require (
@@ -33,24 +35,25 @@ require (
3335
github.com/felixge/httpsnoop v1.0.4 // indirect
3436
github.com/go-logr/logr v1.4.2 // indirect
3537
github.com/go-logr/stdr v1.2.2 // indirect
36-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
38+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
3739
github.com/jackc/pgpassfile v1.0.0 // indirect
3840
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
3941
github.com/jackc/puddle/v2 v2.2.2 // indirect
40-
github.com/klauspost/compress v1.17.10 // indirect
42+
github.com/klauspost/compress v1.17.11 // indirect
4143
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
4244
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
4345
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4446
github.com/prometheus/client_model v0.6.1 // indirect
45-
github.com/prometheus/common v0.60.0 // indirect
47+
github.com/prometheus/common v0.62.0 // indirect
4648
github.com/prometheus/procfs v0.15.1 // indirect
47-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
48-
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
49-
golang.org/x/crypto v0.28.0 // indirect
50-
golang.org/x/net v0.29.0 // indirect
51-
golang.org/x/sys v0.26.0 // indirect
52-
golang.org/x/text v0.19.0 // indirect
53-
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
54-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
55-
google.golang.org/protobuf v1.34.2 // indirect
49+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
50+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 // indirect
51+
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
52+
golang.org/x/crypto v0.32.0 // indirect
53+
golang.org/x/net v0.34.0 // indirect
54+
golang.org/x/sys v0.29.0 // indirect
55+
golang.org/x/text v0.21.0 // indirect
56+
google.golang.org/genproto/googleapis/api v0.0.0-20250124145028-65684f501c47 // indirect
57+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 // indirect
58+
google.golang.org/protobuf v1.36.4 // indirect
5659
)

0 commit comments

Comments
 (0)