From 39ed417398c34c50d001b9db936adbfee6612f7e Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Sat, 18 Jun 2022 15:01:05 +0200 Subject: [PATCH] [feature] Updated go.mod to Go v1.18 and extended log func --- cmd/server/main.go | 5 ++--- go.mod | 2 +- internal/app/log.go | 16 ++++++++++++++++ internal/app/server.go | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 internal/app/log.go diff --git a/cmd/server/main.go b/cmd/server/main.go index 137da91..c7deac3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,7 +3,6 @@ package main import ( "context" "git.pbiernat.dev/golang/rest-api-prototype/internal/app/database" - "log" "net" "os" "os/signal" @@ -22,7 +21,7 @@ const ( func main() { if config.ErrLoadingEnvs != nil { - log.Fatalln("Error loading .env file") + app.Panicf("Error loading .env file") } httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHttpIp), config.GetEnv("SERVER_PORT", defHttpPort)) @@ -30,7 +29,7 @@ func main() { dbc, err := database.Connect(dbConnStr) if err != nil { - log.Panicf("Unable to connect to database: %v\n", err) + app.Panicf("Unable to connect to database: %v\n", err) } env := &handler.Env{httpAddr, dbc} diff --git a/go.mod b/go.mod index 091c6c7..8349e1c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.pbiernat.dev/golang/rest-api-prototype -go 1.17 +go 1.18 require ( github.com/go-ozzo/ozzo-validation v3.6.0+incompatible diff --git a/internal/app/log.go b/internal/app/log.go new file mode 100644 index 0000000..53fe9c1 --- /dev/null +++ b/internal/app/log.go @@ -0,0 +1,16 @@ +package app + +import "log" + +func Panic(v ...any) { + log.Panicln(Name + ":", v) +} + +func Panicf(format string, v ...any) { + log.Panicf(Name + ": " + format, v...) +} + +func Panicln(v ...any) { + v = append([]any{Name + ":"}, v...) + log.Panicln(v...) +} \ No newline at end of file diff --git a/internal/app/server.go b/internal/app/server.go index 33d5967..ffc9f59 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -15,6 +15,8 @@ import ( "git.pbiernat.dev/golang/rest-api-prototype/internal/app/handler" ) +const Name = "REST API Service" + type Server struct { *http.Server }