diff options
author | Yulqen <246857+yulqen@users.noreply.github.com> | 2024-04-22 14:32:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 14:32:43 +0100 |
commit | e546c7103da64e1b4cbda9c400926370f66b8c22 (patch) | |
tree | 58e9e646950efdf934eb287616dfe911a0237dd7 | |
parent | a2630afd4ea8ddf09a95e50c1ce979fc61c7af8b (diff) | |
parent | 979680b2b8fcb0acdf7b9c776bf6e857259c3309 (diff) |
Merge pull request #18 from defencedigital/change-dockerfile
Changed to 1.20 and using RHEL9 Go image
Diffstat (limited to '')
-rw-r--r-- | Dockerfile | 7 | ||||
-rw-r--r-- | cmd/web/helpers.go | 5 | ||||
-rw-r--r-- | cmd/web/main.go | 12 | ||||
-rw-r--r-- | go.mod | 2 |
4 files changed, 12 insertions, 14 deletions
@@ -1,12 +1,11 @@ -FROM docker.io/golang:alpine +FROM registry.redhat.io/rhel9/go-toolset:1.20.12-3.1712567214 WORKDIR /app -RUN apk add --update npm RUN npm i sass govuk-frontend --save COPY go.mod ./ RUN go mod download && go mod verify COPY . . -RUN go build -v -o /usr/local/bin/app ./cmd/web -CMD ["app"] +RUN go build -v -o /app/bin/app ./cmd/web +CMD ["./bin/app"] EXPOSE 4000 diff --git a/cmd/web/helpers.go b/cmd/web/helpers.go index fc9b8f8..882f506 100644 --- a/cmd/web/helpers.go +++ b/cmd/web/helpers.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "log" "net/http" "runtime/debug" ) @@ -14,8 +13,8 @@ func (app *application) serverError(w http.ResponseWriter, r *http.Request, err trace = string(debug.Stack()) ) - app.logger.Error(err.Error(), "method", method, "uri", uri, "trace", trace) - log.Printf("Crash! %s %s %s", method, uri, trace) + app.logger.Printf(err.Error(), method, uri, trace) + app.logger.Printf("Crash! %s %s %s", method, uri, trace) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } diff --git a/cmd/web/main.go b/cmd/web/main.go index 5f4bfdf..bce1f1a 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -4,7 +4,7 @@ import ( "database/sql" "flag" "html/template" - "log/slog" + "log" "net/http" "os" @@ -14,7 +14,7 @@ import ( ) type application struct { - logger *slog.Logger + logger *log.Logger operations *models.OperationModel organisations *models.OrganisationModel persons *models.PersonModel @@ -29,7 +29,7 @@ func main() { //dsn := flag.String("dsn", "postgresql://postgres:secret@ded-db?sslmode=disable", "PostgreSQL data source name") flag.Parse() - logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) + logger := log.New(os.Stdout, "ded-web: ", log.LstdFlags) // Database connection //db, err := openDB(*dsn) @@ -43,7 +43,7 @@ func main() { // initialise the new template cache... templateCache, err := newTemplateCache() if err != nil { - logger.Error(err.Error()) + logger.Println(err.Error()) os.Exit(1) } @@ -59,9 +59,9 @@ func main() { // mux := http.NewServeMux() // mux.HandleFunc("/", home) // log.Print("starting server on :4000") - logger.Info("starting server", "addr", *addr) + logger.Printf("starting server", addr) err = http.ListenAndServe(*addr, app.routes()) - logger.Error(err.Error()) + logger.Println(err.Error()) os.Exit(1) } @@ -1,5 +1,5 @@ module github.com/defencedigital/ded-web -go 1.22.1 +go 1.20 require github.com/lib/pq v1.10.9 |