Skip to content

Commit

Permalink
Deprecate GOCORE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
David Renne authored and David Renne committed Sep 24, 2019
1 parent 779bc29 commit 0ba88b3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 29 deletions.
64 changes: 51 additions & 13 deletions core/dbServices/createDBServices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package dbServices
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"

"github.com/DanielRenne/GoCore/core/extensions"
"github.com/DanielRenne/GoCore/core/serverSettings"

// "fmt"
"encoding/base64"
"io/ioutil"
Expand Down Expand Up @@ -315,6 +318,33 @@ func walkNoSQLVersion(path string, versionDir string) {
finalizeModelFile(versionDir)
}

func download(url string, fileName string) error {

out, errCreateFile := os.Create(fileName)

if errCreateFile != nil {
fmt.Println("Failed to create file handle: " + errCreateFile.Error())
return errCreateFile
}

resp, errHttpGet := http.Get(url)
defer resp.Body.Close()

if errHttpGet != nil {
fmt.Println("Failed to Download file: " + errHttpGet.Error())
return errHttpGet
}

_, errCopyOut := io.Copy(out, resp.Body)

if errCopyOut != nil {
fmt.Println("Failed to Output to " + fileName + ": " + errCopyOut.Error())
return errCopyOut
}
out.Close()
return nil
}

func createNoSQLModel(collections []NOSQLCollection, driver string, versionDir string, scs *schemasCreatedSync) {

//Clean the Model and API Directory
Expand All @@ -331,23 +361,27 @@ func createNoSQLModel(collections []NOSQLCollection, driver string, versionDir s

//Copy Stub Files
if driver == DATABASE_DRIVER_MONGODB {
// copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/mongo/stubs/transaction.go", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/transaction.go")
copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/mongo/stubs/query", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/query.go")
////Support for Long Running Transactions Later Maybe
//copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/mongo/stubs/transactionObjects.go", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/transactionObjects.go")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/mongo/stubs/query", "/tmp/query")
copyNoSQLStub("/tmp/query", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/query.go")
} else if driver == DATABASE_DRIVER_BOLTDB {
copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/bolt/stubs/query", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/query.go")
copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/common/stubs/locales", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/locales.go")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/bolt/stubs/query", "/tmp/query")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/mongo/stubs/locales", "/tmp/locales")
copyNoSQLStub("/tmp/query", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/query.go")
copyNoSQLStub("/tmp/locales", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/locales.go")
}
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/common/stubs/timeZone", "/tmp/timeZone")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/common/stubs/timeZoneLocations", "/tmp/timeZoneLocations")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/common/stubs/locales", "/tmp/locales")

copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/common/stubs/timeZone", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/timeZone.go")
copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/common/stubs/timeZoneLocations", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/timeZoneLocations.go")
copyNoSQLStub(serverSettings.GOCORE_PATH+"/core/dbServices/common/stubs/locales", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/locales.go")
copyNoSQLStub("/tmp/timeZone", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/timeZone.go")
copyNoSQLStub("/tmp/timeZoneLocations", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/timeZoneLocations.go")
copyNoSQLStub("/tmp/locales", serverSettings.APP_LOCATION+"/models/"+versionDir+"/model/locales.go")

var histTemplate []byte
if driver == DATABASE_DRIVER_MONGODB {
var err error
histTemplate, err = extensions.ReadFile(serverSettings.GOCORE_PATH + "/core/dbServices/mongo/stubs/histTemplate")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/mongo/stubs/histTemplate", "/tmp/histTemplate")
histTemplate, err = extensions.ReadFile("/tmp/histTemplate")

if err != nil {
color.Red("Error reading histTemplate.go: " + err.Error())
Expand All @@ -363,7 +397,9 @@ func createNoSQLModel(collections []NOSQLCollection, driver string, versionDir s
} else if driver == DATABASE_DRIVER_BOLTDB {
typeFile = "bolt"
}
transactionTemplate, err := extensions.ReadFile(serverSettings.GOCORE_PATH + "/core/dbServices/" + typeFile + "/stubs/transaction")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/"+typeFile+"/stubs/transaction", "/tmp/transaction")

transactionTemplate, err := extensions.ReadFile("/tmp/transaction")

if err != nil {
color.Red("Error reading transactionTemplate.go: " + err.Error())
Expand Down Expand Up @@ -430,9 +466,11 @@ func initializeModelFile() {
var err error
var modelData []byte
if serverSettings.WebConfig.DbConnection.Driver == DATABASE_DRIVER_MONGODB {
modelData, err = extensions.ReadFile(serverSettings.GOCORE_PATH + "/core/dbServices/mongo/stubs/model")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/mongo/stubs/model", "/tmp/model")
modelData, err = extensions.ReadFile("/tmp/model")
} else {
modelData, err = extensions.ReadFile(serverSettings.GOCORE_PATH + "/core/dbServices/bolt/stubs/model")
download("https://raw.githubusercontent.com/DanielRenne/GoCore/master/core/dbServices/bolt/stubs/model", "/tmp/model")
modelData, err = extensions.ReadFile("/tmp/model")
}

if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions core/goCoreCreateApp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,26 @@ func main() {
err = cmd.Run()
errorOut("running go install on getAppTemplate", err, false)

cmd = exec.Command("go", "run", buildGoFile)
cmd = exec.Command("go", "run", "build"+camelUpper+"/build"+camelUpper+".go")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
errorOut("running go run "+buildGoFile, err, false)

cmd = exec.Command("go", "run", appPath+"/install"+camelUpper+"/install"+camelUpper+".go")
cmd = exec.Command("go", "run", "install"+camelUpper+"/install"+camelUpper+".go")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
errorOut("running "+appPath+"/install"+camelUpper, err, false)

err = os.Chdir(appPath + "/bin")
err = os.Chdir(basePath + "/" + appPath + "/bin")
errorOut("cd bin", err, false)

cmd = exec.Command("bash", "format")
err = cmd.Start()
errorOut("formatting all code", err, false)

err = os.Chdir(appPath)
err = os.Chdir(basePath + "/" + appPath)
errorOut("cd appPath", err, false)

if createGit == "y" {
Expand Down Expand Up @@ -427,7 +427,7 @@ func main() {
if useSSH == "n" {
logger.Message("\n\nRun this after completion.\n\ncd "+os.Getenv("GOPATH")+"/"+appPath+"\ngit push -u "+username+" origin master\n\n\nThen enter your password", logger.MAGENTA)
} else {
err = os.Chdir(appPath)
err = os.Chdir(basePath + "/" + appPath)
errorOut("cd appPath", err, false)
cmd = exec.Command("git", "push", "origin", "master")
cmd.Stdout = os.Stdout
Expand Down
10 changes: 0 additions & 10 deletions core/serverSettings/serverSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"sync"
)

Expand Down Expand Up @@ -95,14 +94,12 @@ type webConfigObj struct {
var WebConfig webConfigObj
var WebConfigMutex sync.RWMutex
var APP_LOCATION string
var GOCORE_PATH string
var SWAGGER_UI_PATH string

func Initialize(path string, configurationFile string) (err error) {

APP_LOCATION = path
SWAGGER_UI_PATH = APP_LOCATION + "/web/swagger/dist"
setGoCorePath()

fmt.Println("core serverSettings initialized.")

Expand Down Expand Up @@ -131,10 +128,3 @@ func Initialize(path string, configurationFile string) (err error) {

return
}

//Sets the GoCore path for go core packages to reference.
func setGoCorePath() {

goPath := os.Getenv("GOPATH")
GOCORE_PATH = goPath + "/src/github.com/DanielRenne/GoCore"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/Masterminds/semver v1.2.2 // indirect
github.com/altipla-consulting/i18n-dateformatter v0.0.0-20150925092426-d7d6ed4b87fb // indirect
github.com/asaskevich/govalidator v0.0.0-20171002085717-ca5f9e638c83 // indirect
github.com/asdine/storm v0.0.0-20160730105259-c9a194eaf968 // indirect
github.com/asdine/storm v0.0.0-20160730105259-c9a194eaf968
github.com/aws/aws-sdk-go v1.10.40-0.20170906173017-58370dfb7321 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/bogdanovich/dns_resolver v0.0.0-20170211073258-a8e42bc6a5b6 // indirect
Expand Down

0 comments on commit 0ba88b3

Please sign in to comment.