Make CRM configurable through .env and part of realize config
This commit is contained in:
+4
-1
@@ -1,2 +1,5 @@
|
||||
SAM_HTTP_ADDR=:3000
|
||||
SAM_DB_DSN=crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci
|
||||
SAM_DB_DSN=crust:crust@tcp(localhost:3306)/crust?collation=utf8mb4_general_ci
|
||||
|
||||
CRM_HTTP_ADDR=:3001
|
||||
CRM_DB_DSN=crust:crust@tcp(localhost:3306)/crust?collation=utf8mb4_general_ci
|
||||
|
||||
+22
-1
@@ -18,7 +18,7 @@ settings:
|
||||
server:
|
||||
status: false
|
||||
schema:
|
||||
- name: crust
|
||||
- name: sam
|
||||
path: cmd/sam
|
||||
commands:
|
||||
vet:
|
||||
@@ -39,3 +39,24 @@ schema:
|
||||
- .git
|
||||
- .realize
|
||||
- vendor
|
||||
- name: crm
|
||||
path: cmd/crm
|
||||
commands:
|
||||
vet:
|
||||
status: true
|
||||
test:
|
||||
status: false
|
||||
run:
|
||||
status: true
|
||||
args:
|
||||
- api
|
||||
watcher:
|
||||
paths:
|
||||
- .
|
||||
- ../../crm
|
||||
extensions:
|
||||
- go
|
||||
ignored_paths:
|
||||
- .git
|
||||
- .realize
|
||||
- vendor
|
||||
|
||||
+24
-3
@@ -9,11 +9,20 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
|
||||
"github.com/crusttech/crust/crm/rest"
|
||||
"github.com/titpetric/factory"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultAddr = ":3000"
|
||||
defaultDsn = "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci"
|
||||
|
||||
envVarKey_HTTP_ADDR = "CRM_HTTP_ADDR"
|
||||
envVarKey_DB_DSN = "CRM_DB_DSN"
|
||||
)
|
||||
|
||||
func handleError(err error, message string) {
|
||||
if message == "" {
|
||||
message = "Error making API call"
|
||||
@@ -24,11 +33,23 @@ func handleError(err error, message string) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// set up flags
|
||||
var envHttpAddr, envDbDsn string
|
||||
var has bool
|
||||
|
||||
if envHttpAddr, has = os.LookupEnv(envVarKey_HTTP_ADDR); !has {
|
||||
envHttpAddr = defaultAddr
|
||||
}
|
||||
|
||||
if envDbDsn, has = os.LookupEnv(envVarKey_DB_DSN); !has {
|
||||
envDbDsn = defaultDsn
|
||||
}
|
||||
|
||||
var (
|
||||
addr = flag.String("addr", ":3000", "Listen address for HTTP server")
|
||||
dsn = flag.String("dsn", "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
// set up flags
|
||||
addr = flag.String("addr", envHttpAddr, "Listen address for HTTP server")
|
||||
dsn = flag.String("dsn", envDbDsn, "DSN for database connection")
|
||||
)
|
||||
println(*dsn)
|
||||
flag.Parse()
|
||||
|
||||
// log to stdout not stderr
|
||||
|
||||
Reference in New Issue
Block a user