From 69b41791027aa57186267385fa6ada62d0f54d50 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Thu, 21 Apr 2022 23:35:49 +0200 Subject: [PATCH] [fix] Fixed empty response --- internal/app/config/env.go | 3 --- internal/app/handler/handler.go | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/app/config/env.go b/internal/app/config/env.go index bb3742d..f08d8ff 100644 --- a/internal/app/config/env.go +++ b/internal/app/config/env.go @@ -12,9 +12,6 @@ func init() { ErrLoadingEnvs = godotenv.Load() } -func init() { -} - func GetEnv(name, defVal string) string { env := os.Getenv(name) if env == "" { diff --git a/internal/app/handler/handler.go b/internal/app/handler/handler.go index d7ef416..ca313d5 100644 --- a/internal/app/handler/handler.go +++ b/internal/app/handler/handler.go @@ -68,7 +68,9 @@ func encodeResponse(w http.ResponseWriter, res *response, err error) { } w.WriteHeader(res.Status) - json.NewEncoder(w).Encode(res.Data) + if res.Data != nil { + json.NewEncoder(w).Encode(res.Data) + } } func encodeError(w http.ResponseWriter, status int, e error) {