From 900e69e95b32d7dc6e3e341145bda89c126dfd6c Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Thu, 31 Oct 2024 09:25:36 +0100
Subject: [PATCH] OZG-6747 remove envconfig

---
 go.mod                         |  1 -
 go.sum                         |  2 --
 internal/config/config.go      |  8 +----
 internal/config/config_test.go | 55 ----------------------------------
 4 files changed, 1 insertion(+), 65 deletions(-)

diff --git a/go.mod b/go.mod
index 7e9c904..29dade4 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,6 @@ go 1.23.0
 
 require (
 	github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
-	github.com/kelseyhightower/envconfig v1.4.0
 	github.com/stretchr/testify v1.9.0
 	google.golang.org/grpc v1.64.0
 	gopkg.in/yaml.v3 v3.0.1
diff --git a/go.sum b/go.sum
index 36447c3..a45d8ab 100644
--- a/go.sum
+++ b/go.sum
@@ -5,8 +5,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 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/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
-github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
 github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
 github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
diff --git a/internal/config/config.go b/internal/config/config.go
index 49ecde6..52be8d2 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -26,7 +26,6 @@
 package config
 
 import (
-	"github.com/kelseyhightower/envconfig"
 	"gopkg.in/yaml.v3"
 	"log"
 	"os"
@@ -48,7 +47,7 @@ type Config struct {
 	Grpc struct {
 		Server struct {
 			Mock bool `yaml:"mock"`
-			Port int  `yaml:"port" envconfig:"GRPC_SERVER_PORT"`
+			Port int  `yaml:"port"`
 		} `yaml:"server"`
 		Router struct {
 			Port int `yaml:"port"`
@@ -85,10 +84,5 @@ func LoadConfig(configFilePath ...string) Config {
 		log.Fatalf("FATAL: error unmarshalling YAML file: %v", err)
 	}
 
-	err = envconfig.Process("", &config)
-	if err != nil {
-		log.Fatalf("FATAL: error reading env: %v", err)
-	}
-
 	return config
 }
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 341e7b3..8a66f9f 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -26,9 +26,7 @@
 package config
 
 import (
-	"os"
 	"testing"
-
 	"github.com/stretchr/testify/assert"
 )
 
@@ -46,57 +44,4 @@ func TestLoadConfig(t *testing.T) {
 		assert.Equal(t, expectedConfig, config)
 	})
 
-	t.Run("should load config from env", func(t *testing.T) {
-		envVars := map[string]string{
-			"HTTP_SERVER_PORT": "9090",
-			"GRPC_SERVER_PORT": "1234",
-			"GRPC_ROUTER_PORT": "5678",
-			"LOGGING_LEVEL":    "ERROR",
-		}
-
-		for key, value := range envVars {
-			assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
-		}
-
-		config := LoadConfig("testdata/empty_test_config.yml")
-
-		for key := range envVars {
-			assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
-		}
-
-		expectedConfig := Config{}
-		expectedConfig.Grpc.Server.Mock = false
-		expectedConfig.Http.Server.Port = 9090
-		expectedConfig.Grpc.Server.Port = 1234
-		expectedConfig.Grpc.Router.Port = 5678
-		expectedConfig.Logging.Level = "ERROR"
-
-		assert.Equal(t, expectedConfig, config)
-	})
-
-	t.Run("should overwrite config with env", func(t *testing.T) {
-		envVars := map[string]string{
-			"HTTP_SERVER_PORT": "9090",
-			"GRPC_SERVER_PORT": "1234",
-		}
-
-		for key, value := range envVars {
-			assert.NoError(t, os.Setenv(key, value), "Setenv "+key+" should not return an error")
-		}
-
-		config := LoadConfig()
-
-		for key := range envVars {
-			assert.NoError(t, os.Unsetenv(key), "Unsetenv "+key+" should not return an error")
-		}
-
-		expectedConfig := Config{}
-		expectedConfig.Grpc.Server.Mock = false
-		expectedConfig.Http.Server.Port = 9090
-		expectedConfig.Grpc.Server.Port = 1234
-		expectedConfig.Grpc.Router.Port = 50051
-		expectedConfig.Logging.Level = "DEBUG"
-
-		assert.Equal(t, expectedConfig, config)
-	})
 }
-- 
GitLab