mirror of
https://github.com/beego/bee.git
synced 2024-11-21 18:40:54 +00:00
go vet
go simple golint structcheck staticcheck unused unconvert
This commit is contained in:
parent
3d5b13d84e
commit
feea8877c0
@ -16,8 +16,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/beego/bee/cmd/commands"
|
||||
_ "github.com/beego/bee/cmd/commands/api"
|
||||
_ "github.com/beego/bee/cmd/commands/bale"
|
||||
@ -79,7 +77,6 @@ Use {{"bee help" | bold}} for more information.
|
||||
|
||||
func Usage() {
|
||||
utils.Tmpl(usageTemplate, commands.AvailableCommands)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func Help(args []string) {
|
||||
|
@ -57,7 +57,7 @@ var CmdApiapp = &commands.Command{
|
||||
└── user.go
|
||||
`,
|
||||
PreRun: func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() },
|
||||
Run: createapi,
|
||||
Run: createAPI,
|
||||
}
|
||||
var apiconf = `appname = {{.Appname}}
|
||||
httpport = 8080
|
||||
@ -139,7 +139,7 @@ func init() {
|
||||
}
|
||||
`
|
||||
|
||||
var ApiModels = `package models
|
||||
var APIModels = `package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -194,7 +194,7 @@ func Delete(ObjectId string) {
|
||||
|
||||
`
|
||||
|
||||
var ApiModels2 = `package models
|
||||
var APIModels2 = `package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -543,7 +543,7 @@ func init() {
|
||||
commands.AvailableCommands = append(commands.AvailableCommands, CmdApiapp)
|
||||
}
|
||||
|
||||
func createapi(cmd *commands.Command, args []string) int {
|
||||
func createAPI(cmd *commands.Command, args []string) int {
|
||||
output := cmd.Out()
|
||||
|
||||
if len(args) < 1 {
|
||||
@ -551,10 +551,13 @@ func createapi(cmd *commands.Command, args []string) int {
|
||||
}
|
||||
|
||||
if len(args) > 1 {
|
||||
cmd.Flag.Parse(args[1:])
|
||||
err := cmd.Flag.Parse(args[1:])
|
||||
if err != nil {
|
||||
beeLogger.Log.Error(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
apppath, packpath, err := utils.CheckEnv(args[0])
|
||||
appPath, packPath, err := utils.CheckEnv(args[0])
|
||||
if err != nil {
|
||||
beeLogger.Log.Fatalf("%s", err)
|
||||
}
|
||||
@ -564,30 +567,30 @@ func createapi(cmd *commands.Command, args []string) int {
|
||||
|
||||
beeLogger.Log.Info("Creating API...")
|
||||
|
||||
os.MkdirAll(apppath, 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", apppath, "\x1b[0m")
|
||||
os.Mkdir(path.Join(apppath, "conf"), 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "conf"), "\x1b[0m")
|
||||
os.Mkdir(path.Join(apppath, "controllers"), 0755)
|
||||
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)
|
||||
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"),
|
||||
os.MkdirAll(appPath, 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", appPath, "\x1b[0m")
|
||||
os.Mkdir(path.Join(appPath, "conf"), 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "conf"), "\x1b[0m")
|
||||
os.Mkdir(path.Join(appPath, "controllers"), 0755)
|
||||
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)
|
||||
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 != "" {
|
||||
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(maingoContent, "{{.DriverName}}", string(generate.SQLDriver), -1)
|
||||
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(mainGoContent, "{{.DriverName}}", string(generate.SQLDriver), -1)
|
||||
if generate.SQLDriver == "mysql" {
|
||||
maingoContent = strings.Replace(maingoContent, "{{.DriverPkg}}", `_ "github.com/go-sql-driver/mysql"`, -1)
|
||||
mainGoContent = strings.Replace(mainGoContent, "{{.DriverPkg}}", `_ "github.com/go-sql-driver/mysql"`, -1)
|
||||
} else if generate.SQLDriver == "postgres" {
|
||||
maingoContent = strings.Replace(maingoContent, "{{.DriverPkg}}", `_ "github.com/lib/pq"`, -1)
|
||||
mainGoContent = strings.Replace(mainGoContent, "{{.DriverPkg}}", `_ "github.com/lib/pq"`, -1)
|
||||
}
|
||||
utils.WriteToFile(path.Join(apppath, "main.go"),
|
||||
utils.WriteToFile(path.Join(appPath, "main.go"),
|
||||
strings.Replace(
|
||||
maingoContent,
|
||||
mainGoContent,
|
||||
"{{.conn}}",
|
||||
generate.SQLConn.String(),
|
||||
-1,
|
||||
@ -596,38 +599,38 @@ func createapi(cmd *commands.Command, args []string) int {
|
||||
beeLogger.Log.Infof("Using '%s' as 'driver'", generate.SQLDriver)
|
||||
beeLogger.Log.Infof("Using '%s' as 'conn'", generate.SQLConn)
|
||||
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 {
|
||||
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")
|
||||
os.Mkdir(path.Join(apppath, "routers"), 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "routers")+string(path.Separator), "\x1b[0m")
|
||||
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")
|
||||
os.Mkdir(path.Join(appPath, "routers"), 0755)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "routers")+string(path.Separator), "\x1b[0m")
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "controllers", "object.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "controllers", "object.go"),
|
||||
strings.Replace(apiControllers, "{{.Appname}}", packpath, -1))
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers", "object.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "controllers", "object.go"),
|
||||
strings.Replace(apiControllers, "{{.Appname}}", packPath, -1))
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "controllers", "user.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "controllers", "user.go"),
|
||||
strings.Replace(apiControllers2, "{{.Appname}}", packpath, -1))
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "controllers", "user.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "controllers", "user.go"),
|
||||
strings.Replace(apiControllers2, "{{.Appname}}", packPath, -1))
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "tests", "default_test.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "tests", "default_test.go"),
|
||||
strings.Replace(apiTests, "{{.Appname}}", packpath, -1))
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "tests", "default_test.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "tests", "default_test.go"),
|
||||
strings.Replace(apiTests, "{{.Appname}}", packPath, -1))
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "routers", "router.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "routers", "router.go"),
|
||||
strings.Replace(apirouter, "{{.Appname}}", packpath, -1))
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "routers", "router.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "routers", "router.go"),
|
||||
strings.Replace(apirouter, "{{.Appname}}", packPath, -1))
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "models", "object.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "models", "object.go"), ApiModels)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "models", "object.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "models", "object.go"), APIModels)
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "models", "user.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "models", "user.go"), ApiModels2)
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "models", "user.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "models", "user.go"), APIModels2)
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "main.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "main.go"),
|
||||
strings.Replace(apiMaingo, "{{.Appname}}", packpath, -1))
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(appPath, "main.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(appPath, "main.go"),
|
||||
strings.Replace(apiMaingo, "{{.Appname}}", packPath, -1))
|
||||
}
|
||||
beeLogger.Log.Success("New API successfully created!")
|
||||
return 0
|
||||
|
@ -143,7 +143,7 @@ func saveFile(filePath string, b []byte) (int, error) {
|
||||
|
||||
var resFiles = make([]string, 0, 10)
|
||||
|
||||
func walkFn(resPath string, info os.FileInfo, err error) error {
|
||||
func walkFn(resPath string, info os.FileInfo, _ error) error {
|
||||
if info.IsDir() || filterSuffix(resPath) {
|
||||
return nil
|
||||
}
|
||||
|
@ -105,10 +105,10 @@ func createhprose(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, "models"), "\x1b[0m")
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "models", "object.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "models", "object.go"), apiapp.ApiModels)
|
||||
utils.WriteToFile(path.Join(apppath, "models", "object.go"), apiapp.APIModels)
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "models", "user.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "models", "user.go"), apiapp.ApiModels2)
|
||||
utils.WriteToFile(path.Join(apppath, "models", "user.go"), apiapp.APIModels2)
|
||||
|
||||
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "main.go"), "\x1b[0m")
|
||||
utils.WriteToFile(path.Join(apppath, "main.go"),
|
||||
|
@ -178,10 +178,8 @@ func RunApp(cmd *commands.Command, args []string) int {
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-exit:
|
||||
runtime.Goexit()
|
||||
}
|
||||
<-exit
|
||||
runtime.Goexit()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ func GetBeegoVersion() string {
|
||||
return ""
|
||||
}
|
||||
if gopath == "" {
|
||||
err = fmt.Errorf("You need to set GOPATH environment variable")
|
||||
beeLogger.Log.Error("You need to set GOPATH environment variable")
|
||||
return ""
|
||||
}
|
||||
wgopath := path.SplitList(gopath)
|
||||
|
@ -19,7 +19,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
@ -98,32 +97,22 @@ func loadConfig() {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if fileInfo.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if fileInfo.Name() == "bee.json" {
|
||||
switch fileInfo.Name() {
|
||||
case "bee.json":
|
||||
beeLogger.Log.Info("Loading configuration from 'bee.json'...")
|
||||
err = parseJSON(path, &Conf)
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to parse JSON file: %s", err)
|
||||
return err
|
||||
}
|
||||
return io.EOF
|
||||
}
|
||||
|
||||
if fileInfo.Name() == "Beefile" {
|
||||
return parseJSON(path, &Conf)
|
||||
case "Beefile":
|
||||
beeLogger.Log.Info("Loading configuration from 'Beefile'...")
|
||||
err = parseYAML(path, &Conf)
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to parse YAML file: %s", err)
|
||||
return err
|
||||
}
|
||||
return io.EOF
|
||||
return parseYAML(path, &Conf)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
beeLogger.Log.Errorf("Failed to parse config file: %s", err)
|
||||
}
|
||||
// Check format version
|
||||
if Conf.Version != confVer {
|
||||
beeLogger.Log.Warn("Your configuration file is outdated. Please do consider updating it.")
|
||||
|
@ -732,7 +732,7 @@ func getModel(str string) (objectname string, m swagger.Schema, realTypes []stri
|
||||
func parseObject(d *ast.Object, k string, m *swagger.Schema, realTypes *[]string, astPkgs map[string]*ast.Package, packageName string) {
|
||||
ts, ok := d.Decl.(*ast.TypeSpec)
|
||||
if !ok {
|
||||
// beeLogger.Log.Fatalf("Unknown type without TypeSec: %v\n", d)
|
||||
beeLogger.Log.Fatalf("Unknown type without TypeSec: %v\n", d)
|
||||
}
|
||||
// TODO support other types, such as `ArrayType`, `MapType`, `InterfaceType` etc...
|
||||
st, ok := ts.Type.(*ast.StructType)
|
||||
|
2
main.go
2
main.go
@ -23,6 +23,8 @@ func main() {
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.Usage()
|
||||
os.Exit(2)
|
||||
return
|
||||
}
|
||||
|
||||
if args[0] == "help" {
|
||||
|
@ -28,7 +28,7 @@ func Notify(text, title string) {
|
||||
}
|
||||
|
||||
func osxNotify(text, title string) {
|
||||
cmd := &exec.Cmd{}
|
||||
var cmd *exec.Cmd
|
||||
if existTerminalNotifier() {
|
||||
cmd = exec.Command("terminal-notifier", "-title", appName, "-message", text, "-subtitle", title)
|
||||
} else if MacOSVersionSupport() {
|
||||
@ -53,13 +53,9 @@ func existTerminalNotifier() bool {
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return false
|
||||
} else {
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
err = cmd.Wait()
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func MacOSVersionSupport() bool {
|
||||
|
@ -320,7 +320,7 @@ func CheckEnv(appname string) (apppath, packpath string, err error) {
|
||||
apppath = path.Join(gosrcpath, appname)
|
||||
|
||||
if _, e := os.Stat(apppath); !os.IsNotExist(e) {
|
||||
err = fmt.Errorf("Cannot create application without removing '%s' first.", apppath)
|
||||
err = fmt.Errorf("Cannot create application without removing '%s' first", apppath)
|
||||
beeLogger.Log.Errorf("Path '%s' already exists", apppath)
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user