From c407945109ff59e34d45459a77e979c2a9f10253 Mon Sep 17 00:00:00 2001 From: Tarcisio Gruppi Date: Fri, 11 Jan 2019 15:13:42 -0200 Subject: [PATCH] Added Config.DatabaseAddress This allows the server to connect to a MySQL server in a different machine. --- config.json.sample | 3 ++- core/model/types/config.go | 23 ++++++++++++----------- core/server.go | 11 ++++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/config.json.sample b/config.json.sample index f38ab93..591aeef 100644 --- a/config.json.sample +++ b/config.json.sample @@ -4,10 +4,11 @@ "ApiPrefix": "", "KeyFile": "", "CertFile": "", + "DatabaseAddress": "", "Database": "openaccounting", "User": "openaccounting", "Password": "openaccounting", "SendgridKey": "", "SendgridEmail": "noreply@domain.com", "SendgridSender": "Sender" -} \ No newline at end of file +} diff --git a/core/model/types/config.go b/core/model/types/config.go index 92b1ef0..58c28c0 100644 --- a/core/model/types/config.go +++ b/core/model/types/config.go @@ -1,15 +1,16 @@ package types type Config struct { - WebUrl string - Port int - ApiPrefix string - KeyFile string - CertFile string - Database string - User string - Password string - SendgridKey string - SendgridEmail string - SendgridSender string + WebUrl string + Port int + ApiPrefix string + KeyFile string + CertFile string + DatabaseAddress string + Database string + User string + Password string + SendgridKey string + SendgridEmail string + SendgridSender string } diff --git a/core/server.go b/core/server.go index 817bac9..354ee4a 100644 --- a/core/server.go +++ b/core/server.go @@ -2,16 +2,17 @@ package main import ( "encoding/json" + "log" + "net/http" + "os" + "strconv" + "github.com/openaccounting/oa-server/core/api" "github.com/openaccounting/oa-server/core/auth" "github.com/openaccounting/oa-server/core/model" "github.com/openaccounting/oa-server/core/model/db" "github.com/openaccounting/oa-server/core/model/types" "github.com/openaccounting/oa-server/core/util" - "log" - "net/http" - "os" - "strconv" //"fmt" ) @@ -31,7 +32,7 @@ func main() { log.Fatal(err) } - connectionString := config.User + ":" + config.Password + "@/" + config.Database + connectionString := config.User + ":" + config.Password + "@" + config.DatabaseAddress + "/" + config.Database db, err := db.NewDB(connectionString)