Skip to content

Package upgrades and more #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions README.md

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion cmd/server/grpc/grpc.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package grpc

import "github.com/naughtygopher/goapp/internal/api"
import (
"context"

"github.com/naughtygopher/goapp/internal/api"
)

type GRPC struct {
apis api.Server
}

func (gr *GRPC) Shutdown(ctx context.Context) error {
_ = ctx
return nil
}

func New(apis api.Server) *GRPC {
return &GRPC{
apis: apis,
Expand Down
23 changes: 2 additions & 21 deletions cmd/server/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"runtime/debug"

"github.com/bnkamalesh/errors"
"github.com/bnkamalesh/webgo/v7"
"github.com/naughtygopher/errors"
"github.com/naughtygopher/webgo/v7"

"github.com/naughtygopher/goapp/internal/api"
"github.com/naughtygopher/goapp/internal/pkg/logger"
Expand All @@ -29,13 +29,6 @@ func (h *Handlers) routes() []*webgo.Route {
Handlers: []http.HandlerFunc{errWrapper(h.HelloWorld)},
TrailingSlash: true,
},
{
Name: "health",
Pattern: "/-/health",
Method: http.MethodGet,
Handlers: []http.HandlerFunc{errWrapper(h.Health)},
TrailingSlash: true,
},
{
Name: "create-user",
Pattern: "/users",
Expand All @@ -53,18 +46,6 @@ func (h *Handlers) routes() []*webgo.Route {
}
}

// Health is the HTTP handler to return the status of the app including the version, and other details
// This handler uses webgo to respond to the http request
func (h *Handlers) Health(w http.ResponseWriter, r *http.Request) error {
out, err := h.apis.ServerHealth()
if err != nil {
return err
}
webgo.R200(w, out)
return nil
}

// HelloWorld is a helloworld HTTP handler
func (h *Handlers) HelloWorld(w http.ResponseWriter, r *http.Request) error {
contentType := r.Header.Get("Content-Type")
switch contentType {
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/http/handlers_usernotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"net/http"

"github.com/bnkamalesh/errors"
"github.com/naughtygopher/errors"
"github.com/naughtygopher/goapp/internal/usernotes"
"github.com/bnkamalesh/webgo/v7"
"github.com/naughtygopher/webgo/v7"
)

func (h *Handlers) CreateUserNote(w http.ResponseWriter, r *http.Request) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/http/handlers_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"net/http"

"github.com/bnkamalesh/errors"
"github.com/bnkamalesh/webgo/v7"
"github.com/naughtygopher/errors"
"github.com/naughtygopher/webgo/v7"

"github.com/naughtygopher/goapp/internal/users"
)
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strings"
"time"

"github.com/bnkamalesh/errors"
"github.com/naughtygopher/errors"
"github.com/naughtygopher/goapp/internal/api"
"github.com/naughtygopher/goapp/internal/pkg/apm"
"github.com/bnkamalesh/webgo/v7"
"github.com/bnkamalesh/webgo/v7/middleware/accesslog"
"github.com/naughtygopher/webgo/v7"
"github.com/naughtygopher/webgo/v7/middleware/accesslog"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.22 AS builder
FROM golang:1.23 AS builder

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

Expand All @@ -23,7 +23,7 @@ RUN adduser --home "/appuser" --disabled-password appuser \
--gecos "appuser,-,-,-"
USER appuser

COPY --from=builder /app/internal/server/http/web /home/appuser/app/web
COPY --from=builder /app/cmd/server/http/web /home/appuser/app/web
COPY --from=builder /app/appbin /home/appuser/app

ENV TEMPLATES_BASEPATH=/home/appuser/app/web/templates
Expand Down
16 changes: 5 additions & 11 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
version: "3.9"
services:
redis:
image: "redis:7"
networks:
- goapp_network

postgres:
image: "postgres:16"
image: "postgres:17"
environment:
POSTGRES_PASSWORD: gauserpassword
POSTGRES_USER: gauser
Expand All @@ -17,9 +11,9 @@ services:
- goapp_network

goapp:
image: golang:1.22
image: golang:1.23
volumes:
- ${PWD}:/app
- ${PWD}/../:/app
working_dir: /app
tty: true
environment:
Expand All @@ -29,11 +23,11 @@ services:
POSTGRES_STORENAME: "goapp"
POSTGRES_USERNAME: "gauser"
POSTGRES_PASSWORD: "gauserpassword"
command: go run main.go
command: ["go", "run", "inits.go", "shutdown.go", "main.go"]
ports:
- "8080:8080"
- "2000:2000"
depends_on:
- redis
- postgres
networks:
- goapp_network
Expand Down
67 changes: 35 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
module github.com/naughtygopher/goapp

go 1.22
go 1.22.0

require (
github.com/Masterminds/squirrel v1.5.4
github.com/bnkamalesh/errors v0.11.1
github.com/bnkamalesh/webgo/v7 v7.0.1
github.com/exaring/otelpgx v0.8.0
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.7.1
github.com/prometheus/client_golang v1.20.4
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0
go.opentelemetry.io/contrib/propagators/b3 v1.30.0
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.30.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0
go.opentelemetry.io/otel/exporters/prometheus v0.52.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.30.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.30.0
go.opentelemetry.io/otel/metric v1.30.0
go.opentelemetry.io/otel/sdk v1.30.0
go.opentelemetry.io/otel/sdk/metric v1.30.0
go.opentelemetry.io/otel/trace v1.30.0
golang.org/x/sync v0.8.0
google.golang.org/grpc v1.67.1
github.com/jackc/pgx/v5 v5.7.2
github.com/naughtygopher/errors v1.0.1
github.com/naughtygopher/proberesponder v0.6.3
github.com/naughtygopher/webgo/v7 v7.0.5
github.com/prometheus/client_golang v1.20.5
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0
go.opentelemetry.io/contrib/propagators/b3 v1.34.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.34.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.34.0
go.opentelemetry.io/otel/exporters/prometheus v0.56.0
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.34.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.34.0
go.opentelemetry.io/otel/metric v1.34.0
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/sdk/metric v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
golang.org/x/sync v0.10.0
google.golang.org/grpc v1.70.0
)

require (
Expand All @@ -33,24 +35,25 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.60.0 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240930140551-af27646dc61f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect
google.golang.org/protobuf v1.34.2 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250124145028-65684f501c47 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250124145028-65684f501c47 // indirect
google.golang.org/protobuf v1.36.4 // indirect
)
Loading
Loading