|
|
@@ -183,6 +183,8 @@ func (c *EngineClient) GenSwagger(xmlfile string){
|
|
|
server := "http://swagger.qianqiusoft.com"
|
|
|
server += "/api/v1/upload"
|
|
|
|
|
|
+ fmt.Println("===========================================================================>11")
|
|
|
+
|
|
|
request, err := newfileUploadRequest(server, nil, "xmlfile", xmlfile)
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
|
@@ -296,39 +298,63 @@ func (c *EngineClient)MergeXmlToSingle()string{
|
|
|
func scanControllers(ctrldir string) ([]XmlController, error){
|
|
|
_, err := os.Stat(ctrldir)
|
|
|
if os.IsNotExist(err) {
|
|
|
- fmt.Println("controller dir does not exist")
|
|
|
+ fmt.Println("controller dir does not exist", err.Error())
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
controllers := []XmlController{}
|
|
|
- err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return filepath.SkipDir
|
|
|
- }
|
|
|
- if info.IsDir(){
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
+ filePaths := []string{}
|
|
|
+ filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
+ if err != nil{
|
|
|
+ fmt.Println("controller getAllFile error", err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range filePaths {
|
|
|
ctrl := XmlController{}
|
|
|
- ctrlfile := ctrldir + "/" + info.Name()
|
|
|
+ ctrlfile := filePaths[i]
|
|
|
_, err = os.Stat(ctrlfile)
|
|
|
if os.IsNotExist(err) {
|
|
|
fmt.Println("controller xml file " + ctrlfile + " does not exist")
|
|
|
- return filepath.SkipDir
|
|
|
+ return controllers, err
|
|
|
}
|
|
|
bytess, _ := ioutil.ReadFile(ctrlfile)
|
|
|
err = xml.Unmarshal(bytess, &ctrl)
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
- return filepath.SkipDir
|
|
|
+ return controllers, err
|
|
|
}
|
|
|
controllers = append(controllers, ctrl)
|
|
|
-
|
|
|
- return nil
|
|
|
- })
|
|
|
-
|
|
|
- return controllers, err
|
|
|
+ }
|
|
|
+ return controllers, nil
|
|
|
+
|
|
|
+ //err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
+ //
|
|
|
+ // if err != nil {
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // if info.IsDir(){
|
|
|
+ // return nil
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // ctrl := XmlController{}
|
|
|
+ // ctrlfile := ctrldir + "/" + info.Name()
|
|
|
+ // _, err = os.Stat(ctrlfile)
|
|
|
+ // if os.IsNotExist(err) {
|
|
|
+ // fmt.Println("controller xml file " + ctrlfile + " does not exist")
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // bytess, _ := ioutil.ReadFile(ctrlfile)
|
|
|
+ // err = xml.Unmarshal(bytess, &ctrl)
|
|
|
+ // if err != nil{
|
|
|
+ // fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // controllers = append(controllers, ctrl)
|
|
|
+ //
|
|
|
+ // return nil
|
|
|
+ //})
|
|
|
+
|
|
|
+ //return controllers, err
|
|
|
}
|
|
|
|
|
|
func scanBeans(ctrldir string) ([]XmlBean, error){
|
|
|
@@ -339,34 +365,58 @@ func scanBeans(ctrldir string) ([]XmlBean, error){
|
|
|
}
|
|
|
|
|
|
beans := []XmlBean{}
|
|
|
- err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return filepath.SkipDir
|
|
|
- }
|
|
|
- if info.IsDir(){
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- bean := XmlBean{}
|
|
|
- beanfile := ctrldir + "/" + info.Name()
|
|
|
- _, err = os.Stat(beanfile)
|
|
|
+ filePaths := []string{}
|
|
|
+ filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
+ if err != nil{
|
|
|
+ fmt.Println("controller getAllFile error", err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range filePaths {
|
|
|
+ ctrl := XmlBean{}
|
|
|
+ ctrlfile := filePaths[i]
|
|
|
+ _, err = os.Stat(ctrlfile)
|
|
|
if os.IsNotExist(err) {
|
|
|
- fmt.Println("controller xml file " + beanfile + " does not exist")
|
|
|
- return filepath.SkipDir
|
|
|
+ fmt.Println("controller xml file " + ctrlfile + " does not exist")
|
|
|
+ return beans, err
|
|
|
}
|
|
|
- bytess, _ := ioutil.ReadFile(beanfile)
|
|
|
- err = xml.Unmarshal(bytess, &bean)
|
|
|
- if err != nil{
|
|
|
+ bytess, _ := ioutil.ReadFile(ctrlfile)
|
|
|
+ err = xml.Unmarshal(bytess, &ctrl)
|
|
|
+ if err != nil {
|
|
|
fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
- return filepath.SkipDir
|
|
|
+ return beans, err
|
|
|
}
|
|
|
- beans = append(beans, bean)
|
|
|
-
|
|
|
- return nil
|
|
|
- })
|
|
|
-
|
|
|
- return beans, err
|
|
|
+ beans = append(beans, ctrl)
|
|
|
+ }
|
|
|
+ return beans, nil
|
|
|
+
|
|
|
+ //err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
+ //
|
|
|
+ // if err != nil {
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // if info.IsDir(){
|
|
|
+ // return nil
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // bean := XmlBean{}
|
|
|
+ // beanfile := ctrldir + "/" + info.Name()
|
|
|
+ // _, err = os.Stat(beanfile)
|
|
|
+ // if os.IsNotExist(err) {
|
|
|
+ // fmt.Println("controller xml file " + beanfile + " does not exist")
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // bytess, _ := ioutil.ReadFile(beanfile)
|
|
|
+ // err = xml.Unmarshal(bytess, &bean)
|
|
|
+ // if err != nil{
|
|
|
+ // fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // beans = append(beans, bean)
|
|
|
+ //
|
|
|
+ // return nil
|
|
|
+ //})
|
|
|
+ //
|
|
|
+ //return beans, err
|
|
|
}
|
|
|
|
|
|
func scanTables(ctrldir string) ([]XmlTable, error){
|
|
|
@@ -377,34 +427,58 @@ func scanTables(ctrldir string) ([]XmlTable, error){
|
|
|
}
|
|
|
|
|
|
tables := []XmlTable{}
|
|
|
- err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return filepath.SkipDir
|
|
|
- }
|
|
|
- if info.IsDir(){
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- table := XmlTable{}
|
|
|
- tablefile := ctrldir + "/" + info.Name()
|
|
|
- _, err = os.Stat(tablefile)
|
|
|
+ filePaths := []string{}
|
|
|
+ filePaths, err = getAllFile(strings.TrimSuffix(ctrldir, "/"), filePaths)
|
|
|
+ if err != nil{
|
|
|
+ fmt.Println("controller getAllFile error", err.Error())
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ for i := range filePaths {
|
|
|
+ ctrl := XmlTable{}
|
|
|
+ ctrlfile := filePaths[i]
|
|
|
+ _, err = os.Stat(ctrlfile)
|
|
|
if os.IsNotExist(err) {
|
|
|
- fmt.Println("controller xml file " + tablefile + " does not exist")
|
|
|
- return filepath.SkipDir
|
|
|
+ fmt.Println("controller xml file " + ctrlfile + " does not exist")
|
|
|
+ return tables, err
|
|
|
}
|
|
|
- bytess, _ := ioutil.ReadFile(tablefile)
|
|
|
- err = xml.Unmarshal(bytess, &table)
|
|
|
- if err != nil{
|
|
|
+ bytess, _ := ioutil.ReadFile(ctrlfile)
|
|
|
+ err = xml.Unmarshal(bytess, &ctrl)
|
|
|
+ if err != nil {
|
|
|
fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
- return filepath.SkipDir
|
|
|
+ return tables, err
|
|
|
}
|
|
|
- tables = append(tables, table)
|
|
|
-
|
|
|
- return nil
|
|
|
- })
|
|
|
-
|
|
|
- return tables, err
|
|
|
+ tables = append(tables, ctrl)
|
|
|
+ }
|
|
|
+ return tables, nil
|
|
|
+
|
|
|
+ //err = filepath.Walk(ctrldir, func(path string, info os.FileInfo, err error) error {
|
|
|
+ //
|
|
|
+ // if err != nil {
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // if info.IsDir(){
|
|
|
+ // return nil
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // table := XmlTable{}
|
|
|
+ // tablefile := ctrldir + "/" + info.Name()
|
|
|
+ // _, err = os.Stat(tablefile)
|
|
|
+ // if os.IsNotExist(err) {
|
|
|
+ // fmt.Println("controller xml file " + tablefile + " does not exist")
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // bytess, _ := ioutil.ReadFile(tablefile)
|
|
|
+ // err = xml.Unmarshal(bytess, &table)
|
|
|
+ // if err != nil{
|
|
|
+ // fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
|
|
|
+ // return filepath.SkipDir
|
|
|
+ // }
|
|
|
+ // tables = append(tables, table)
|
|
|
+ //
|
|
|
+ // return nil
|
|
|
+ //})
|
|
|
+ //
|
|
|
+ //return tables, err
|
|
|
}
|
|
|
|
|
|
func createVueApisFolder(controllers []XmlController){
|
|
|
@@ -414,6 +488,30 @@ func createVueApisFolder(controllers []XmlController){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func getAllFile(pathname string, s []string) ([]string, error) {
|
|
|
+ rd, err := ioutil.ReadDir(pathname)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("read dir fail:", err)
|
|
|
+ return s, err
|
|
|
+ }
|
|
|
+ for _, fi := range rd {
|
|
|
+ if fi.IsDir() {
|
|
|
+ fullDir := pathname + "/" + fi.Name()
|
|
|
+ s, err = getAllFile(fullDir, s)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("read dir fail:", err)
|
|
|
+ return s, err
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if strings.HasSuffix(strings.ToLower(fi.Name()), ".xml") {
|
|
|
+ fullName := pathname + "/" + fi.Name()
|
|
|
+ s = append(s, fullName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return s, nil
|
|
|
+}
|
|
|
+
|
|
|
func unzipbytes(bs *bytes.Buffer) bytes.Buffer {
|
|
|
r, _ := gzip.NewReader(bs)
|
|
|
defer r.Close()
|