Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Conf = "./cmd/conf/db.toml" Out = "./models" NewCRUDCmd = &cobra.Command{ Use: "new-crud", Short: "Create the model code for the CRUD.", Long: `Create the model code for the CRUD, You can view subcommands and customize builds`, RunE: func(cmd *cobra.Command, args []string) (err error) { tl := crud.CrudTemplate() s2 := crud.NewTable2Struct() dc := DBConf{} if err = configure(&dc, Conf); err != nil { return } list, err := s2.Dsn(dc.Addr).Run() if err != nil { return err } for index := 0; index < len(list); index++ { pdata := map[string]interface{}{ "Name": list[index].Name, "Content": list[index].Content, } var pf *os.File pf, err = os.Create(Out + "/" + list[index].TableRealName + ".go") if err != nil { return err } tmpl, err := template.New("").Parse(tl) if err = tmpl.Execute(pf, pdata); err != nil { return err } } exec.Command("gofmt", "-w", Out).Output() return nil }} )
View Source
var ( NewProjectCmd = &cobra.Command{ Use: "new-project [project_name]", Short: "New a microservice project based on freedom", Long: `New project from freedom project template. `, RunE: func(cmd *cobra.Command, args []string) (err error) { sysPath, err := filepath.Abs(args[0]) if err != nil { return } projectPath := strings.Replace(sysPath, build.Default.GOPATH+"/src/", "", 1) projectName := args[0] pdata := map[string]interface{}{ "PackagePath": projectPath, "PackageName": projectName, } mkdirAll(sysPath) m := project.FileContent() for filepath, content := range m { var pf *os.File pf, err = os.Create(sysPath + filepath) if err != nil { return err } tmpl, err := template.New(projectName).Parse(content) if err = tmpl.Execute(pf, pdata); err != nil { return err } } exec.Command("gofmt", "-w", sysPath).Output() return nil }, } )
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.