Skip to content

Commit

Permalink
env: add workdir prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed Oct 12, 2020
1 parent 08c01b8 commit eb96a7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
28 changes: 4 additions & 24 deletions candihelper/const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package candihelper

import (
"errors"
"time"
)

Expand All @@ -10,8 +9,6 @@ const (
TimeZoneAsia = "Asia/Jakarta"
// TokenClaimKey const
TokenClaimKey = "tokenClaim"
// TokenKey const
TokenKey = "18608c7d-b319-0xc000165c80-0xc0000da000-11478e4e2650"

// TimeFormatLogger const
TimeFormatLogger = "2006/01/02 15:04:05"
Expand All @@ -21,33 +18,21 @@ const (
// V2 const
V2 = "/v2"

// GRPCBanner const
GRPCBanner = ` __________ ____ ______
/ ____/ __ \/ __ \/ ____/
/ / __/ /_/ / /_/ / /
/ /_/ / _, _/ ____/ /___
\____/_/ |_/_/ \____/
`

// RedisBanner const
RedisBanner = ` ____ __________ _________
/ __ \/ ____/ __ \/ _/ ___/
/ /_/ / __/ / / / // / \__ \
/ _, _/ /___/ /_/ // / ___/ /
/_/ |_/_____/_____/___//____/
`

// Byte ...
Byte uint64 = 1
// KByte ...
KByte = Byte * 1024
// MByte ...
MByte = KByte * 1024

// WORKDIR const for workdir environment
WORKDIR = "WORKDIR"
// RepositorySQL unit of work for sql repository
RepositorySQL = "repositorySQL"
// RepositoryMongo unit of work for mongodb repository
RepositoryMongo = "repositoryMongo"
// UsecaseUOW unit of work for usecase
UsecaseUOW = "usecaseUOW"
)

var (
Expand All @@ -68,11 +53,6 @@ var (
// Reset color
Reset = []byte{27, 91, 48, 109}

// ErrTokenFormat var
ErrTokenFormat = errors.New("Invalid token format")
// ErrTokenExpired var
ErrTokenExpired = errors.New("Token is expired")

// AsiaJakartaLocalTime location
AsiaJakartaLocalTime *time.Location
)
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type Config struct {
}

// Init app config
func Init(rootApp string) *Config {
loadBaseEnv(rootApp, &env)
func Init() *Config {
loadBaseEnv(&env)
return &Config{}
}

Expand Down
7 changes: 5 additions & 2 deletions config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/joho/godotenv"
"pkg.agungdwiprasetyo.com/candi/candihelper"
"pkg.agungdwiprasetyo.com/candi/logger"
)

Expand Down Expand Up @@ -61,10 +62,10 @@ type Env struct {
}
}

func loadBaseEnv(serviceLocation string, targetEnv *Env) {
func loadBaseEnv(targetEnv *Env) {

// load main .env and additional .env in app
if err := godotenv.Load(serviceLocation + ".env"); err != nil {
if err := godotenv.Load(os.Getenv(candihelper.WORKDIR) + ".env"); err != nil {
logger.LogYellow("warning: cannot load .env")
}

Expand Down Expand Up @@ -177,9 +178,11 @@ func loadBaseEnv(serviceLocation string, targetEnv *Env) {
if env.UseGraphQL && !ok {
panic("GRAPHQL is active, missing GRAPHQL_SCHEMA_DIR environment")
}
env.GraphQLSchemaDir = os.Getenv(candihelper.WORKDIR) + env.GraphQLSchemaDir

env.JSONSchemaDir, ok = os.LookupEnv("JSON_SCHEMA_DIR")
if !ok {
panic("missing JSON_SCHEMA_DIR environment")
}
env.JSONSchemaDir = os.Getenv(candihelper.WORKDIR) + env.JSONSchemaDir
}

0 comments on commit eb96a7f

Please sign in to comment.