mirror of
https://github.com/beego/bee.git
synced 2024-11-24 13:30:53 +00:00
cmd/api: put sqlconn to app.conf
This commit is contained in:
parent
393e315ba5
commit
cb2fae3e68
@ -65,6 +65,7 @@ runmode = dev
|
|||||||
autorender = false
|
autorender = false
|
||||||
copyrequestbody = true
|
copyrequestbody = true
|
||||||
EnableDocs = true
|
EnableDocs = true
|
||||||
|
sqlconn = {{.SQLConnStr}}
|
||||||
`
|
`
|
||||||
var apiMaingo = `package main
|
var apiMaingo = `package main
|
||||||
|
|
||||||
@ -93,11 +94,8 @@ import (
|
|||||||
{{.DriverPkg}}
|
{{.DriverPkg}}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
orm.RegisterDataBase("default", "{{.DriverName}}", "{{.conn}}")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
orm.RegisterDataBase("default", "{{.DriverName}}", beego.AppConfig.String("sqlconn"))
|
||||||
if beego.BConfig.RunMode == "dev" {
|
if beego.BConfig.RunMode == "dev" {
|
||||||
beego.BConfig.WebConfig.DirectoryIndex = true
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
||||||
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
||||||
@ -558,6 +556,7 @@ func createAPI(cmd *commands.Command, args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appPath, packPath, err := utils.CheckEnv(args[0])
|
appPath, packPath, err := utils.CheckEnv(args[0])
|
||||||
|
appName := path.Base(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Fatalf("%s", err)
|
beeLogger.Log.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
@ -575,11 +574,13 @@ func createAPI(cmd *commands.Command, args []string) int {
|
|||||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers"), "\x1b[0m")
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers"), "\x1b[0m")
|
||||||
os.Mkdir(path.Join(appPath, "tests"), 0755)
|
os.Mkdir(path.Join(appPath, "tests"), 0755)
|
||||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "tests"), "\x1b[0m")
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "tests"), "\x1b[0m")
|
||||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf", "app.conf"), "\x1b[0m")
|
|
||||||
utils.WriteToFile(path.Join(appPath, "conf", "app.conf"),
|
|
||||||
strings.Replace(apiconf, "{{.Appname}}", path.Base(args[0]), -1))
|
|
||||||
|
|
||||||
if generate.SQLConn != "" {
|
if generate.SQLConn != "" {
|
||||||
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf", "app.conf"), "\x1b[0m")
|
||||||
|
confContent := strings.Replace(apiconf, "{{.Appname}}", appName, -1)
|
||||||
|
confContent = strings.Replace(confContent, "{{.SQLConnStr}}", generate.SQLConn.String(), -1)
|
||||||
|
utils.WriteToFile(path.Join(appPath, "conf", "app.conf"), confContent)
|
||||||
|
|
||||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "main.go"), "\x1b[0m")
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "main.go"), "\x1b[0m")
|
||||||
mainGoContent := strings.Replace(apiMainconngo, "{{.Appname}}", packPath, -1)
|
mainGoContent := strings.Replace(apiMainconngo, "{{.Appname}}", packPath, -1)
|
||||||
mainGoContent = strings.Replace(mainGoContent, "{{.DriverName}}", string(generate.SQLDriver), -1)
|
mainGoContent = strings.Replace(mainGoContent, "{{.DriverName}}", string(generate.SQLDriver), -1)
|
||||||
@ -601,6 +602,11 @@ func createAPI(cmd *commands.Command, args []string) int {
|
|||||||
beeLogger.Log.Infof("Using '%s' as 'tables'", generate.Tables)
|
beeLogger.Log.Infof("Using '%s' as 'tables'", generate.Tables)
|
||||||
generate.GenerateAppcode(string(generate.SQLDriver), string(generate.SQLConn), "3", string(generate.Tables), appPath)
|
generate.GenerateAppcode(string(generate.SQLDriver), string(generate.SQLConn), "3", string(generate.Tables), appPath)
|
||||||
} else {
|
} else {
|
||||||
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf", "app.conf"), "\x1b[0m")
|
||||||
|
confContent := strings.Replace(apiconf, "{{.Appname}}", appName, -1)
|
||||||
|
confContent = strings.Replace(confContent, "{{.SQLConnStr}}", "", -1)
|
||||||
|
utils.WriteToFile(path.Join(appPath, "conf", "app.conf"), confContent)
|
||||||
|
|
||||||
os.Mkdir(path.Join(appPath, "models"), 0755)
|
os.Mkdir(path.Join(appPath, "models"), 0755)
|
||||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "models"), "\x1b[0m")
|
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "models"), "\x1b[0m")
|
||||||
os.Mkdir(path.Join(appPath, "routers"), 0755)
|
os.Mkdir(path.Join(appPath, "routers"), 0755)
|
||||||
|
Loading…
Reference in New Issue
Block a user