Skip to content

Commit

Permalink
Renovate Update module github.com/ministryofjustice/opg-go-common to …
Browse files Browse the repository at this point in the history
…v1 (#403)

* Renovate Update module github.com/ministryofjustice/opg-go-common to v1

* fix linting errors

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Kate Smith <kate.smith@digital.justice.gov.uk>
  • Loading branch information
renovate[bot] and kate-49 authored Jul 1, 2024
1 parent 72d92f0 commit 8b39264
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 20 deletions.
27 changes: 25 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
module github.com/ministryofjustice/opg-sirius-supervision-deputy-hub

go 1.21
go 1.22

toolchain go1.22.4

require (
github.com/gorilla/mux v1.8.1
github.com/ministryofjustice/opg-go-common v0.0.0-20231128145056-24628fba649c
github.com/ministryofjustice/opg-go-common v1.4.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)

require (
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20221221133751-67e37ae746cd // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opentelemetry.io/contrib/detectors/aws/ecs v1.27.0 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.27.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
45 changes: 45 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20221221133751-67e37ae746cd h1:C0dfBzAdNMqxokqWUysk2KTJSMmqvh9cNW1opdy5+0Q=
github.com/brunoscheufler/aws-ecs-metadata-go v0.0.0-20221221133751-67e37ae746cd/go.mod h1:CeKhh8xSs3WZAc50xABMxu+FlfAAd5PNumo7NfOv7EE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/ministryofjustice/opg-go-common v0.0.0-20231106092059-b3dcf8bd1eeb/go.mod h1:qktwZb46YkojkLVHU2QNnVK6yVktXkNpBuJ+TyobvuY=
github.com/ministryofjustice/opg-go-common v0.0.0-20231128145056-24628fba649c h1:598i3upKVEHRLW+eSkGmCaV7+yIaFTV6lMiHOC3tXDY=
github.com/ministryofjustice/opg-go-common v0.0.0-20231128145056-24628fba649c/go.mod h1:qktwZb46YkojkLVHU2QNnVK6yVktXkNpBuJ+TyobvuY=
github.com/ministryofjustice/opg-go-common v1.4.0 h1:UjtBKWFX/MxWOk3cuUxvjM5qSxUv0u8J+ntPM336xyE=
github.com/ministryofjustice/opg-go-common v1.4.0/go.mod h1:uz6eLy9zp095mnWzBUbwzYjoaoHdCvTmowVC6IZ0Jxg=
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=
Expand All @@ -21,11 +34,43 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/contrib/detectors/aws/ecs v1.27.0 h1:3VwT2JwYqorDQZS5CGnKD5OAQ6iTlD7kgDZV9vUXR9o=
go.opentelemetry.io/contrib/detectors/aws/ecs v1.27.0/go.mod h1:uqNiuQtZU5YjW2mu58xptApZaxxDJefKrSd+QaAMoWw=
go.opentelemetry.io/contrib/propagators/aws v1.27.0 h1:RJexJi4R0S9CpxzuhhzGlTCIpaaK9SJH9g9BFrCWfPE=
go.opentelemetry.io/contrib/propagators/aws v1.27.0/go.mod h1:bqU5Ma1dEQ7VtRbPMUsH8UDTuTMiLJN4W+eUmyNVayc=
go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ=
go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik=
go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak=
go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI=
go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A=
go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw=
go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 h1:AgADTJarZTBqgjiUzRgfaBchgYB3/WFTC80GPwsMcRI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
7 changes: 4 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package server

import (
"github.com/gorilla/mux"
"github.com/ministryofjustice/opg-go-common/logging"
"github.com/ministryofjustice/opg-go-common/securityheaders"
"github.com/ministryofjustice/opg-go-common/telemetry"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/sirius"
"html/template"
"io"
"log/slog"
"net/http"
"net/url"
)
Expand Down Expand Up @@ -40,14 +41,14 @@ type Template interface {
ExecuteTemplate(io.Writer, string, interface{}) error
}

func New(logger *logging.Logger, client Client, templates map[string]*template.Template, envVars EnvironmentVars) http.Handler {
func New(logger *slog.Logger, client Client, templates map[string]*template.Template, envVars EnvironmentVars) http.Handler {
wrap := wrapHandler(logger, client, templates["error.gotmpl"], envVars)

router := mux.NewRouter().StrictSlash(true)
router.Handle("/health-check", healthCheck())

pageRouter := router.PathPrefix("/{id}").Subrouter()
pageRouter.Use(logging.Use(logger))
pageRouter.Use(telemetry.Middleware(logger))

pageRouter.Handle("",
wrap(
Expand Down
30 changes: 26 additions & 4 deletions internal/server/wrap_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package server

import (
"fmt"
"github.com/ministryofjustice/opg-go-common/logging"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/sirius"
"log/slog"
"net/http"
)

Expand Down Expand Up @@ -42,7 +42,29 @@ type DeputyHubClient interface {
GetDeputyDetails(sirius.Context, int, int, int) (sirius.DeputyDetails, error)
}

func wrapHandler(logger *logging.Logger, client DeputyHubClient, tmplError Template, envVars EnvironmentVars) func(next Handler) http.Handler {
type ExpandedError interface {
Title() string
Data() interface{}
}

func LoggerRequest(l *slog.Logger, r *http.Request, err error) {
if ee, ok := err.(ExpandedError); ok {
l.Info(ee.Title(),
slog.String("request_method", r.Method),
slog.String("request_uri", r.URL.String()),
slog.Any("data", ee.Data()))
} else if err != nil {
l.Info(err.Error(),
slog.String("request_method", r.Method),
slog.String("request_uri", r.URL.String()))
} else {
l.Info("",
slog.String("request_method", r.Method),
slog.String("request_uri", r.URL.String()))
}
}

func wrapHandler(logger *slog.Logger, client DeputyHubClient, tmplError Template, envVars EnvironmentVars) func(next Handler) http.Handler {
return func(next Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars, err := NewAppVars(client, r, envVars)
Expand All @@ -68,7 +90,7 @@ func wrapHandler(logger *logging.Logger, client DeputyHubClient, tmplError Templ
return
}

logger.Request(r, err)
LoggerRequest(logger, r, err)

code := http.StatusInternalServerError
if serverStatusError, ok := err.(StatusError); ok {
Expand All @@ -87,7 +109,7 @@ func wrapHandler(logger *logging.Logger, client DeputyHubClient, tmplError Templ
err = tmplError.ExecuteTemplate(w, "page", errVars)

if err != nil {
logger.Request(r, err)
LoggerRequest(logger, r, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
Expand Down
5 changes: 2 additions & 3 deletions internal/server/wrap_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package server

import (
"errors"
"github.com/ministryofjustice/opg-go-common/logging"
"github.com/ministryofjustice/opg-go-common/telemetry"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/sirius"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"strconv"
"testing"
)
Expand Down Expand Up @@ -51,7 +50,7 @@ func (m *mockNext) GetHandler() Handler {
}
}

var logger = logging.New(os.Stdout, "test ")
var logger = telemetry.NewLogger("test ")

func Test_wrapHandler_successful_request(t *testing.T) {
w := httptest.NewRecorder()
Expand Down
17 changes: 9 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"github.com/ministryofjustice/opg-go-common/paginate"
"html/template"
"log"
Expand All @@ -13,14 +14,14 @@ import (
"syscall"
"time"

"github.com/ministryofjustice/opg-go-common/logging"
"github.com/ministryofjustice/opg-go-common/telemetry"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/server"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/sirius"
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/util"
)

func main() {
logger := logging.New(os.Stdout, "opg-sirius-supervision-deputy-hub ")
logger := telemetry.NewLogger("opg-sirius-supervision-deputy-hub ")
// manually set time zone
if tz := os.Getenv("TZ"); tz != "" {
var err error
Expand All @@ -32,7 +33,7 @@ func main() {

envVars, err := server.NewEnvironmentVars()
if err != nil {
logger.Fatal(err)
logger.Info(err.Error())
}

layouts, _ := template.
Expand Down Expand Up @@ -76,7 +77,7 @@ func main() {

client, err := sirius.NewClient(http.DefaultClient, envVars.SiriusURL)
if err != nil {
logger.Fatal(err)
logger.Info(err.Error())
}

server := &http.Server{
Expand All @@ -86,22 +87,22 @@ func main() {

go func() {
if err := server.ListenAndServe(); err != nil {
logger.Fatal(err)
logger.Info(err.Error())
}
}()

logger.Print("Running at :" + envVars.Port)
logger.Info("Running at :" + envVars.Port)

c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)

sig := <-c
logger.Print("signal received: ", sig)
logger.Info(fmt.Sprint("signal received: ", sig))

tc, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

if err := server.Shutdown(tc); err != nil {
logger.Print(err)
logger.Info(err.Error())
}
}

0 comments on commit 8b39264

Please sign in to comment.