From 72b8836c2440c58f0e4c8750ee8471983cd9bf55 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 16 Jan 2024 23:46:11 +0700 Subject: [PATCH 1/9] feat: add env --- .env.template | 22 ++++++++++++++++++++++ Makefile | 2 +- tools/export-env.sh | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .env.template create mode 100644 tools/export-env.sh diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..b11a372 --- /dev/null +++ b/.env.template @@ -0,0 +1,22 @@ +APP_PORT=3004 +APP_ENV=development +APP_SECRET=secret + +DB_URL=postgres://root:root@localhost:5432/johnjud_db + +JWT_SECRET=secret +JWT_EXPIRES_IN=3600 +JWT_REFRESH_TOKEN_TTL=604800 +JWT_ISSUER=issuer +JWT_RESET_TOKEN_TTL=900 + +REDIS_HOST=localhost +REDIS_PORT=6379 +REDIS_PASSWORD= + +AUTH_CLIENT_URL=http://localhost:3000 + +SENDGRID_API_KEY=api_key +SENDGRID_NAME=johnjud +SENDGRID_ADDRESS=johnjud@gmail.com + diff --git a/Makefile b/Makefile index 4f6ced1..a92bc59 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ server: - go run ./cmd/. + . ./tools/export-env.sh ; go run ./cmd/. mock-gen: mockgen -source ./pkg/repository/cache/cache.repository.go -destination ./mocks/repository/cache/cache.mock.go diff --git a/tools/export-env.sh b/tools/export-env.sh new file mode 100644 index 0000000..39688ee --- /dev/null +++ b/tools/export-env.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +## Usage: +## . ./export-env.sh ; $COMMAND +## . ./export-env.sh ; echo ${MINIENTREGA_FECHALIMITE} + +unamestr=$(uname) +if [ "$unamestr" = 'Linux' ]; then + + export $(grep -v '^#' .env | xargs -d '\n') + +elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then + + export $(grep -v '^#' .env | xargs -0) + +fi \ No newline at end of file From f370c12e66c22c78435d18d1987297c84a55acb8 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 16 Jan 2024 23:46:25 +0700 Subject: [PATCH 2/9] fix: cfgldr --- cfgldr/config.go | 114 ++++++++++++++++++++++++++++++----------------- cmd/main.go | 15 ++++--- 2 files changed, 81 insertions(+), 48 deletions(-) diff --git a/cfgldr/config.go b/cfgldr/config.go index b934608..cba9a27 100644 --- a/cfgldr/config.go +++ b/cfgldr/config.go @@ -1,74 +1,106 @@ package cfgldr import ( - "github.com/pkg/errors" "github.com/spf13/viper" ) type Database struct { - Host string `mapstructure:"host"` - Port int `mapstructure:"port"` - Name string `mapstructure:"name"` - Username string `mapstructure:"username"` - Password string `mapstructure:"password"` - SSL string `mapstructure:"ssl"` + Url string `mapstructure:"URL"` } type App struct { - Port int `mapstructure:"port"` - Debug bool `mapstructure:"debug"` - Secret string `mapstructure:"secret"` + Port int `mapstructure:"PORT"` + Env string `mapstructure:"ENV"` + Secret string `mapstructure:"SECRET"` } type Jwt struct { - Secret string `mapstructure:"secret"` - ExpiresIn int `mapstructure:"expires_in"` - RefreshTokenTTL int `mapstructure:"refresh_token_ttl"` - Issuer string `mapstructure:"issuer"` - ResetTokenTTL int `mapstructure:"reset_token_ttl"` + Secret string `mapstructure:"SECRET"` + ExpiresIn int `mapstructure:"EXPIRES_IN"` + RefreshTokenTTL int `mapstructure:"REFRESH_TOKEN_TTL"` + Issuer string `mapstructure:"ISSUER"` + ResetTokenTTL int `mapstructure:"RESET_TOKEN_TTL"` } type Redis struct { - Host string `mapstructure:"host"` - Port int `mapstructure:"port"` - Password string `mapstructure:"password"` + Host string `mapstructure:"HOST"` + Port int `mapstructure:"PORT"` + Password string `mapstructure:"PASSWORD"` } type Auth struct { - ClientURL string `mapstructure:"client_url"` + ClientURL string `mapstructure:"CLIENT_URL"` } type Sendgrid struct { - ApiKey string `mapstructure:"api_key"` - Name string `mapstructure:"name"` - Address string `mapstructure:"address"` + ApiKey string `mapstructure:"API_KEY"` + Name string `mapstructure:"NAME"` + Address string `mapstructure:"ADDRESS"` } type Config struct { - App App `mapstructure:"app"` - Database Database `mapstructure:"database"` - Jwt Jwt `mapstructure:"jwt"` - Redis Redis `mapstructure:"redis"` - Auth Auth `mapstructure:"auth"` - Sendgrid Sendgrid `mapstructure:"sendgrid"` + App App + Database Database + Jwt Jwt + Redis Redis + Auth Auth + Sendgrid Sendgrid } -func LoadConfig() (config *Config, err error) { - viper.AddConfigPath("./config") - viper.SetConfigName("config") - viper.SetConfigType("yaml") - - viper.AutomaticEnv() +func LoadConfig() (*Config, error) { + dbCfgLdr := viper.New() + dbCfgLdr.SetEnvPrefix("DB") + dbCfgLdr.AutomaticEnv() + dbCfgLdr.AllowEmptyEnv(false) + dbConfig := Database{} + if err := dbCfgLdr.Unmarshal(&dbConfig); err != nil { + return nil, err + } - err = viper.ReadInConfig() - if err != nil { - return nil, errors.Wrap(err, "error occurs while reading the config") + appCfgLdr := viper.New() + appCfgLdr.SetEnvPrefix("APP") + appCfgLdr.AutomaticEnv() + dbCfgLdr.AllowEmptyEnv(false) + appConfig := App{} + if err := appCfgLdr.Unmarshal(&appConfig); err != nil { + return nil, err } - err = viper.Unmarshal(&config) - if err != nil { - return nil, errors.Wrap(err, "error occurs while unmarshal the config") + jwtConfig := &Jwt{} + LoadEnvGroup(jwtConfig, "JWT") + + redisConfig := &Redis{} + LoadEnvGroup(redisConfig, "REDIS") + + authConfig := &Auth{} + LoadEnvGroup(authConfig, "AUTH") + + sendgridConfig := &Sendgrid{} + LoadEnvGroup(sendgridConfig, "SENDGRID") + + config := &Config{ + Database: dbConfig, + App: appConfig, + Jwt: *jwtConfig, + Redis: *redisConfig, + Auth: *authConfig, + Sendgrid: *sendgridConfig, } - return + return config, nil +} + +func (ac *App) IsDevelopment() bool { + return ac.Env == "development" +} + +func LoadEnvGroup(config interface{}, prefix string) (err error) { + cfgLdr := viper.New() + cfgLdr.SetEnvPrefix(prefix) + cfgLdr.AutomaticEnv() + cfgLdr.AllowEmptyEnv(false) + if err := cfgLdr.Unmarshal(&config); err != nil { + return err + } + return nil } diff --git a/cmd/main.go b/cmd/main.go index 9de5070..940d57f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,6 +3,13 @@ package main import ( "context" "fmt" + "net" + "os" + "os/signal" + "sync" + "syscall" + "time" + "github.com/isd-sgcu/johnjud-auth/cfgldr" "github.com/isd-sgcu/johnjud-auth/database" authRp "github.com/isd-sgcu/johnjud-auth/internal/repository/auth" @@ -13,12 +20,6 @@ import ( jwtSvc "github.com/isd-sgcu/johnjud-auth/internal/service/jwt" tokenSvc "github.com/isd-sgcu/johnjud-auth/internal/service/token" userSvc "github.com/isd-sgcu/johnjud-auth/internal/service/user" - "net" - "os" - "os/signal" - "sync" - "syscall" - "time" "github.com/isd-sgcu/johnjud-auth/internal/strategy" "github.com/isd-sgcu/johnjud-auth/internal/utils" @@ -96,7 +97,7 @@ func main() { Msg("Failed to load config") } - db, err := database.InitPostgresDatabase(&conf.Database, conf.App.Debug) + db, err := database.InitPostgresDatabase(&conf.Database, conf.App.IsDevelopment()) if err != nil { log.Fatal(). Err(err). From 9b15cb33ba079210a72ad93facac12019ff5fdcd Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 16 Jan 2024 23:46:31 +0700 Subject: [PATCH 3/9] fix: postgres conn --- database/postgresql.connection.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/database/postgresql.connection.go b/database/postgresql.connection.go index 60b6a5b..933eb26 100644 --- a/database/postgresql.connection.go +++ b/database/postgresql.connection.go @@ -1,25 +1,21 @@ package database import ( - "fmt" "github.com/isd-sgcu/johnjud-auth/cfgldr" "github.com/isd-sgcu/johnjud-auth/internal/domain/model" "gorm.io/driver/postgres" "gorm.io/gorm" gormLogger "gorm.io/gorm/logger" - "strconv" ) func InitPostgresDatabase(conf *cfgldr.Database, isDebug bool) (db *gorm.DB, err error) { - dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", conf.Host, strconv.Itoa(conf.Port), conf.Username, conf.Password, conf.Name, conf.SSL) - - gormConf := &gorm.Config{TranslateError: true} + gormConf := &gorm.Config{} if !isDebug { gormConf.Logger = gormLogger.Default.LogMode(gormLogger.Silent) } - db, err = gorm.Open(postgres.Open(dsn), gormConf) + db, err = gorm.Open(postgres.Open(conf.Url), gormConf) if err != nil { return nil, err } From b6f069cfa4636b5b1b1dd058b2f471143312bc56 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Tue, 16 Jan 2024 23:55:18 +0700 Subject: [PATCH 4/9] fix: remove config --- config/config.example.yaml | 31 ------------------------ go.mod | 37 ++++++++++++++--------------- go.sum | 48 ++++++++++++++------------------------ 3 files changed, 36 insertions(+), 80 deletions(-) delete mode 100644 config/config.example.yaml diff --git a/config/config.example.yaml b/config/config.example.yaml deleted file mode 100644 index b468695..0000000 --- a/config/config.example.yaml +++ /dev/null @@ -1,31 +0,0 @@ -app: - port: 3002 - debug: true - secret: - -database: - host: localhost - port: 5432 - name: johnjud_db - username: root - password: root - -jwt: - secret: - expires_in: 3600 - refresh_token_ttl: 604800 - issuer: - reset_token_ttl: 900 - -redis: - host: localhost - port: 6379 - password: "" - -auth: - client_url: localhost:3000 - -sendgrid: - api_key: - name: johnjud - address: johnjud@gmail.com \ No newline at end of file diff --git a/go.mod b/go.mod index 126f022..85a07c6 100644 --- a/go.mod +++ b/go.mod @@ -4,18 +4,31 @@ go 1.21.3 toolchain go1.21.5 +require ( + github.com/go-faker/faker/v4 v4.2.0 + github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/golang/mock v1.6.0 + github.com/google/uuid v1.5.0 + github.com/isd-sgcu/johnjud-go-proto v0.5.0 + github.com/pkg/errors v0.9.1 + github.com/redis/go-redis/v9 v9.3.1 + github.com/rs/zerolog v1.31.0 + github.com/sendgrid/sendgrid-go v3.14.0+incompatible + github.com/spf13/viper v1.18.1 + github.com/stretchr/testify v1.8.4 + golang.org/x/crypto v0.17.0 + google.golang.org/grpc v1.60.1 + gorm.io/driver/postgres v1.5.4 + gorm.io/gorm v1.25.5 +) + require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-faker/faker/v4 v4.2.0 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/uuid v1.5.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/isd-sgcu/johnjud-go-proto v0.5.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.4.3 // indirect @@ -24,40 +37,26 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mattn/go-sqlite3 v1.14.17 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/redis/go-redis/v9 v9.3.1 // indirect - github.com/rs/zerolog v1.31.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sendgrid/rest v2.6.9+incompatible // indirect - github.com/sendgrid/sendgrid-go v3.14.0+incompatible // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.18.2 // indirect github.com/stretchr/objx v0.5.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect - golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect - google.golang.org/grpc v1.60.1 // indirect google.golang.org/protobuf v1.32.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/postgres v1.5.4 // indirect - gorm.io/driver/sqlite v1.5.4 // indirect - gorm.io/gorm v1.25.5 // indirect ) diff --git a/go.sum b/go.sum index 74db985..b0b482d 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -7,6 +11,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-faker/faker/v4 v4.2.0 h1:dGebOupKwssrODV51E0zbMrv5e2gO9VWSLNC1WDCpWg= @@ -20,16 +26,12 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/isd-sgcu/johnjud-go-proto v0.0.8 h1:nIQBZgK2OFVrLjVtpeDgwows8poA7LhsIVE4hlbBC1o= -github.com/isd-sgcu/johnjud-go-proto v0.0.8/go.mod h1:HP0w9gC30b5WNnqeFBM9JJZud+pvyikz0+pGFSI/Wjw= -github.com/isd-sgcu/johnjud-go-proto v0.1.2 h1:gp1MGHCnJdeuUEI4yCbvpQJ1BfLzR9Tr9Q1kKSdssME= -github.com/isd-sgcu/johnjud-go-proto v0.1.2/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4= -github.com/isd-sgcu/johnjud-go-proto v0.1.5 h1:ZhMb73xXOSM2OlsfQ8wv6rmbfSIrXwbBumIx/vtdgHc= -github.com/isd-sgcu/johnjud-go-proto v0.1.5/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4= github.com/isd-sgcu/johnjud-go-proto v0.5.0 h1:GgqRzWjya5p1yhfU/kpX8i4WL42+qT2TkyXZmssH6B4= github.com/isd-sgcu/johnjud-go-proto v0.5.0/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -42,6 +44,10 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +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= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -49,8 +55,6 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= -github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= @@ -62,6 +66,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/redis/go-redis/v9 v9.3.1 h1:KqdY8U+3X6z+iACvumCNxnoluToB+9Me+TvyFa21Mds= github.com/redis/go-redis/v9 v9.3.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= @@ -81,8 +87,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= -github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= +github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM= +github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= @@ -102,20 +108,14 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos= -golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -128,41 +128,31 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 h1:SeZZZx0cP0fqUyA+oRzP9k7cSwJlvDFiROO72uwD6i0= -google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I= google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc= google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -170,7 +160,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo= gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0= -gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0= -gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= From fb05690d16b611c0946f79f58be3914b2f7d6e7e Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Wed, 17 Jan 2024 00:00:37 +0700 Subject: [PATCH 5/9] feat: prod compose --- Dockerfile | 6 ----- docker-compose-prod.yaml | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 docker-compose-prod.yaml diff --git a/Dockerfile b/Dockerfile index 707c676..77e3d24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,9 +16,6 @@ COPY . . # Build the application RUN go build -o server ./cmd/main.go -# Copy config files -COPY ./config ./config - # Adding the grpc_health_probe RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \ wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ @@ -36,9 +33,6 @@ COPY --from=base /bin/grpc_health_probe ./ # Copy execute file COPY --from=base /app/server ./ -# Copy config files -COPY --from=base /app/config ./config - # Set ENV to production ENV GO_ENV production diff --git a/docker-compose-prod.yaml b/docker-compose-prod.yaml new file mode 100644 index 0000000..e5c18ee --- /dev/null +++ b/docker-compose-prod.yaml @@ -0,0 +1,56 @@ +version: "3" + +services: + auth: + container_name: johnjud-auth + restart: unless-stopped + build: . + ports: + - 3002:3002 + environment: + - APP_PORT=3004 + - APP_ENV=development + - APP_SECRET=secret + - DB_URL=postgres://root:root@johnjud-local-db:5432/johnjud_db + - JWT_SECRET=secret + - JWT_EXPIRES_IN=3600 + - JWT_REFRESH_TOKEN_TTL=604800 + - JWT_ISSUER=issuer + - JWT_RESET_TOKEN_TTL=900 + - REDIS_HOST=localhost + - REDIS_PORT=6379 + - REDIS_PASSWORD= + - AUTH_CLIENT_URL=http://localhost:3000 + - SENDGRID_API_KEY=api_key + - SENDGRID_NAME=johnjud + - SENDGRID_ADDRESS=johnjud@gmail.com + networks: + - johnjud + + local-db: + image: postgres:15.1-alpine3.17 + container_name: johnjud-local-db + restart: unless-stopped + environment: + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: johnjud_db + volumes: + - postgres:/var/lib/postgresql/data + ports: + - "5432:5432" + networks: + - johnjud + + cache: + image: redis + restart: unless-stopped + ports: + - "6379:6379" + networks: + - johnjud + +volumes: + postgres: +networks: + johnjud: \ No newline at end of file From 584dea7795b90aca03d6ca108f46e14f93da2580 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Wed, 17 Jan 2024 00:15:03 +0700 Subject: [PATCH 6/9] fix: config --- cfgldr/config.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/cfgldr/config.go b/cfgldr/config.go index cba9a27..5b303b6 100644 --- a/cfgldr/config.go +++ b/cfgldr/config.go @@ -48,23 +48,11 @@ type Config struct { } func LoadConfig() (*Config, error) { - dbCfgLdr := viper.New() - dbCfgLdr.SetEnvPrefix("DB") - dbCfgLdr.AutomaticEnv() - dbCfgLdr.AllowEmptyEnv(false) dbConfig := Database{} - if err := dbCfgLdr.Unmarshal(&dbConfig); err != nil { - return nil, err - } + LoadEnvGroup(&dbConfig, "DB") - appCfgLdr := viper.New() - appCfgLdr.SetEnvPrefix("APP") - appCfgLdr.AutomaticEnv() - dbCfgLdr.AllowEmptyEnv(false) appConfig := App{} - if err := appCfgLdr.Unmarshal(&appConfig); err != nil { - return nil, err - } + LoadEnvGroup(&appConfig, "APP") jwtConfig := &Jwt{} LoadEnvGroup(jwtConfig, "JWT") From 33c230a4f2dacdd858a7cb9fdf8011480e86fa83 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Wed, 17 Jan 2024 00:28:44 +0700 Subject: [PATCH 7/9] fix: env --- docker-compose-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-prod.yaml b/docker-compose-prod.yaml index e5c18ee..5db588d 100644 --- a/docker-compose-prod.yaml +++ b/docker-compose-prod.yaml @@ -9,7 +9,7 @@ services: - 3002:3002 environment: - APP_PORT=3004 - - APP_ENV=development + - APP_ENV=production - APP_SECRET=secret - DB_URL=postgres://root:root@johnjud-local-db:5432/johnjud_db - JWT_SECRET=secret From 8e99fca5d9315d45034bb0f208c1a5fec3bedbc0 Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Wed, 17 Jan 2024 01:03:24 +0700 Subject: [PATCH 8/9] fix: config load env --- cfgldr/config.go | 75 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/cfgldr/config.go b/cfgldr/config.go index 5b303b6..609d35d 100644 --- a/cfgldr/config.go +++ b/cfgldr/config.go @@ -48,31 +48,67 @@ type Config struct { } func LoadConfig() (*Config, error) { + dbCfgLdr := viper.New() + dbCfgLdr.SetEnvPrefix("DB") + dbCfgLdr.AutomaticEnv() + dbCfgLdr.AllowEmptyEnv(false) dbConfig := Database{} - LoadEnvGroup(&dbConfig, "DB") + if err := dbCfgLdr.Unmarshal(&dbConfig); err != nil { + return nil, err + } + appCfgLdr := viper.New() + appCfgLdr.SetEnvPrefix("APP") + appCfgLdr.AutomaticEnv() + appCfgLdr.AllowEmptyEnv(false) appConfig := App{} - LoadEnvGroup(&appConfig, "APP") + if err := appCfgLdr.Unmarshal(&appConfig); err != nil { + return nil, err + } - jwtConfig := &Jwt{} - LoadEnvGroup(jwtConfig, "JWT") + jwtCfgLdr := viper.New() + jwtCfgLdr.SetEnvPrefix("JWT") + jwtCfgLdr.AutomaticEnv() + jwtCfgLdr.AllowEmptyEnv(false) + jwtConfig := Jwt{} + if err := jwtCfgLdr.Unmarshal(&jwtConfig); err != nil { + return nil, err + } - redisConfig := &Redis{} - LoadEnvGroup(redisConfig, "REDIS") + redisCfgLdr := viper.New() + redisCfgLdr.SetEnvPrefix("REDIS") + redisCfgLdr.AutomaticEnv() + redisCfgLdr.AllowEmptyEnv(false) + redisConfig := Redis{} + if err := redisCfgLdr.Unmarshal(&redisConfig); err != nil { + return nil, err + } - authConfig := &Auth{} - LoadEnvGroup(authConfig, "AUTH") + authCfgLdr := viper.New() + authCfgLdr.SetEnvPrefix("AUTH") + authCfgLdr.AutomaticEnv() + authCfgLdr.AllowEmptyEnv(false) + authConfig := Auth{} + if err := authCfgLdr.Unmarshal(&authConfig); err != nil { + return nil, err + } - sendgridConfig := &Sendgrid{} - LoadEnvGroup(sendgridConfig, "SENDGRID") + sendgridCfgLdr := viper.New() + sendgridCfgLdr.SetEnvPrefix("SENDRID") + sendgridCfgLdr.AutomaticEnv() + sendgridCfgLdr.AllowEmptyEnv(false) + sendgridConfig := Sendgrid{} + if err := sendgridCfgLdr.Unmarshal(&sendgridConfig); err != nil { + return nil, err + } config := &Config{ Database: dbConfig, App: appConfig, - Jwt: *jwtConfig, - Redis: *redisConfig, - Auth: *authConfig, - Sendgrid: *sendgridConfig, + Jwt: jwtConfig, + Redis: redisConfig, + Auth: authConfig, + Sendgrid: sendgridConfig, } return config, nil @@ -81,14 +117,3 @@ func LoadConfig() (*Config, error) { func (ac *App) IsDevelopment() bool { return ac.Env == "development" } - -func LoadEnvGroup(config interface{}, prefix string) (err error) { - cfgLdr := viper.New() - cfgLdr.SetEnvPrefix(prefix) - cfgLdr.AutomaticEnv() - cfgLdr.AllowEmptyEnv(false) - if err := cfgLdr.Unmarshal(&config); err != nil { - return err - } - return nil -} From c4b6e3c2065ccdaba3250f8d9bb65a19901fd57e Mon Sep 17 00:00:00 2001 From: Idhibhat Pankam Date: Wed, 17 Jan 2024 21:35:11 +0700 Subject: [PATCH 9/9] fix: gorm conf --- database/postgresql.connection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/postgresql.connection.go b/database/postgresql.connection.go index 933eb26..bb7ad24 100644 --- a/database/postgresql.connection.go +++ b/database/postgresql.connection.go @@ -9,7 +9,7 @@ import ( ) func InitPostgresDatabase(conf *cfgldr.Database, isDebug bool) (db *gorm.DB, err error) { - gormConf := &gorm.Config{} + gormConf := &gorm.Config{TranslateError: true} if !isDebug { gormConf.Logger = gormLogger.Default.LogMode(gormLogger.Silent)