Ver código fonte

复制light-engine的sqlconfig文件夹到应用目录

zhangjq 6 anos atrás
pai
commit
ac4915508b
3 arquivos alterados com 116 adições e 1 exclusões
  1. 6 1
      client/engineclient.go
  2. 108 0
      client/utils.go
  3. 2 0
      client/xsd.go

+ 6 - 1
client/engineclient.go

@@ -13,7 +13,7 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
-
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/env"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
 )
 
@@ -94,6 +94,10 @@ func (c *EngineClient) GenerateCurrentProject() {
 		return
 	}
 	c.Generate(projMainXmlFileTemp)
+
+	path, _ := utils.GetCurrentPath()
+	CopyDir(env.Get("GOPATH", "") + "/src/git.qianqiusoft.com/qianqiusoft/light-apiengine/sqlconfig",
+		path+"sqlconfig")
 }
 
 func (c *EngineClient) Generate(xmlfile string) {
@@ -150,6 +154,7 @@ func (c *EngineClient) Generate(xmlfile string) {
 					ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
 				}
 			} else {
+				os.MkdirAll(filepath.Dir(path), os.ModePerm)
 				err := ioutil.WriteFile(path, result.Data[i].Content, os.ModePerm)
 				if err != nil {
 					fmt.Println(err.Error())

+ 108 - 0
client/utils.go

@@ -0,0 +1,108 @@
+package client
+
+import (
+	"os"
+	"fmt"
+	"errors"
+	"time"
+	"strings"
+	"path/filepath"
+	"io"
+)
+
+/**
+ * 拷贝文件夹,同时拷贝文件夹中的文件
+ * @param srcPath  		需要拷贝的文件夹路径: D:/test
+ * @param destPath		拷贝到的位置: D:/backup/
+ */
+func CopyDir(srcPath string, destPath string) error {
+	//检测目录正确性
+	if srcInfo, err := os.Stat(srcPath); err != nil {
+		fmt.Println(err.Error())
+		return err
+	} else {
+		if !srcInfo.IsDir() {
+			e := errors.New("srcPath不是一个正确的目录!")
+			fmt.Println(e.Error())
+			return e
+		}
+	}
+	if destInfo, err := os.Stat(destPath); err != nil {
+		fmt.Println(err.Error())
+		return err
+	} else {
+		if !destInfo.IsDir() {
+			e := errors.New("destInfo不是一个正确的目录!")
+			fmt.Println(e.Error())
+			return e
+		}
+	}
+	//加上拷贝时间:不用可以去掉
+	destPath = destPath + "_" + time.Now().Format("20060102150405")
+
+	err := filepath.Walk(srcPath, func(path string, f os.FileInfo, err error) error {
+		if f == nil {
+			return err
+		}
+		if !f.IsDir() {
+			path := strings.Replace(path, "\\", "/", -1)
+			destNewPath := strings.Replace(path, srcPath, destPath, -1)
+			fmt.Println("复制文件:" + path + " 到 " + destNewPath)
+			copyFile(path, destNewPath)
+		}
+		return nil
+	})
+	if err != nil {
+		fmt.Printf(err.Error())
+	}
+	return err
+}
+
+//生成目录并拷贝文件
+func copyFile(src, dest string) (w int64, err error) {
+	srcFile, err := os.Open(src)
+	if err != nil {
+		fmt.Println(err.Error())
+		return
+	}
+	defer srcFile.Close()
+	//分割path目录
+	destSplitPathDirs := strings.Split(dest, "/")
+
+	//检测时候存在目录
+	destSplitPath := ""
+	for index, dir := range destSplitPathDirs {
+		if index < len(destSplitPathDirs)-1 {
+			destSplitPath = destSplitPath + dir + "/"
+			b, _ := pathExists(destSplitPath)
+			if b == false {
+				fmt.Println("创建目录:" + destSplitPath)
+				//创建目录
+				err := os.Mkdir(destSplitPath, os.ModePerm)
+				if err != nil {
+					fmt.Println(err)
+				}
+			}
+		}
+	}
+	dstFile, err := os.Create(dest)
+	if err != nil {
+		fmt.Println(err.Error())
+		return
+	}
+	defer dstFile.Close()
+
+	return io.Copy(dstFile, srcFile)
+}
+
+//检测文件夹路径时候存在
+func pathExists(path string) (bool, error) {
+	_, err := os.Stat(path)
+	if err == nil {
+		return true, nil
+	}
+	if os.IsNotExist(err) {
+		return false, nil
+	}
+	return false, err
+}

+ 2 - 0
client/xsd.go

@@ -51,6 +51,8 @@ var XSD=`<?xml version="1.0" standalone="yes"?>
                   <xs:attribute name="name" type="xs:string" />
                   <xs:attribute name="desc" type="xs:string" />
                   <xs:attribute name="skip_login" type="xs:string" />
+				  <xs:attribute name="function" type="xs:string" />
+                  <xs:attribute name="table" type="xs:string" />
                 </xs:complexType>
               </xs:element>
             </xs:sequence>