1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 18:40:54 +00:00

Add support for apps outside of gopath with go modules, fixes #549

This commit is contained in:
Franz Wilhelm von der Lippe 2018-10-06 13:35:26 +02:00
parent 5ed819a025
commit 6689e25d6f

View File

@ -79,37 +79,44 @@ func init() {
commands.AvailableCommands = append(commands.AvailableCommands, CmdRun) commands.AvailableCommands = append(commands.AvailableCommands, CmdRun)
} }
// RunApp locates files to watch, and starts the beego application
func RunApp(cmd *commands.Command, args []string) int { func RunApp(cmd *commands.Command, args []string) int {
if len(args) == 0 || args[0] == "watchall" { // The default app path is the current working directory
currpath, _ = os.Getwd() appPath, _ := os.Getwd()
if found, _gopath, _ := utils.SearchGOPATHs(currpath); found {
appname = path.Base(currpath)
currentGoPath = _gopath
} else {
beeLogger.Log.Fatalf("No application '%s' found in your GOPATH", currpath)
}
} else {
// Check if passed Bee application path/name exists in the GOPATH(s)
if found, _gopath, _path := utils.SearchGOPATHs(args[0]); found {
currpath = _path
currentGoPath = _gopath
appname = path.Base(currpath)
} else {
beeLogger.Log.Fatalf("No application '%s' found in your GOPATH", args[0])
}
if strings.HasSuffix(appname, ".go") && utils.IsExist(currpath) { // If an argument is presented, we use it as the app path
if len(args) != 0 && args[0] != "watchall" {
if path.IsAbs(args[0]) {
appPath = args[0]
} else {
appPath = path.Join(appPath, args[0])
}
}
if utils.IsInGOPATH(appPath) {
if found, _gopath, _path := utils.SearchGOPATHs(appPath); found {
appPath = _path
appname = path.Base(appPath)
currentGoPath = _gopath
} else {
beeLogger.Log.Fatalf("No application '%s' found in your GOPATH", appPath)
}
if strings.HasSuffix(appname, ".go") && utils.IsExist(appPath) {
beeLogger.Log.Warnf("The appname is in conflict with file's current path. Do you want to build appname as '%s'", appname) beeLogger.Log.Warnf("The appname is in conflict with file's current path. Do you want to build appname as '%s'", appname)
beeLogger.Log.Info("Do you want to overwrite it? [yes|no] ") beeLogger.Log.Info("Do you want to overwrite it? [yes|no] ")
if !utils.AskForConfirmation() { if !utils.AskForConfirmation() {
return 0 return 0
} }
} }
} else {
beeLogger.Log.Warn("Running application outside of GOPATH")
appname = path.Base(appPath)
currentGoPath = appPath
} }
beeLogger.Log.Infof("Using '%s' as 'appname'", appname) beeLogger.Log.Infof("Using '%s' as 'appname'", appname)
beeLogger.Log.Debugf("Current path: %s", utils.FILE(), utils.LINE(), currpath) beeLogger.Log.Debugf("Current path: %s", utils.FILE(), utils.LINE(), appPath)
if runmode == "prod" || runmode == "dev" { if runmode == "prod" || runmode == "dev" {
os.Setenv("BEEGO_RUNMODE", runmode) os.Setenv("BEEGO_RUNMODE", runmode)
@ -122,7 +129,7 @@ func RunApp(cmd *commands.Command, args []string) int {
} }
var paths []string var paths []string
readAppDirectories(currpath, &paths) readAppDirectories(appPath, &paths)
// Because monitor files has some issues, we watch current directory // Because monitor files has some issues, we watch current directory
// and ignore non-go files. // and ignore non-go files.
@ -159,7 +166,7 @@ func RunApp(cmd *commands.Command, args []string) int {
} }
} }
if downdoc == "true" { if downdoc == "true" {
if _, err := os.Stat(path.Join(currpath, "swagger", "index.html")); err != nil { if _, err := os.Stat(path.Join(appPath, "swagger", "index.html")); err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
downloadFromURL(swaggerlink, "swagger.zip") downloadFromURL(swaggerlink, "swagger.zip")
unzipAndDelete("swagger.zip") unzipAndDelete("swagger.zip")