浏览代码

add attr named dir to controller

huangrf 6 年之前
父节点
当前提交
65087a5317
共有 2 个文件被更改,包括 17 次插入6 次删除
  1. 10 0
      client/engineclient.go
  2. 7 6
      client/struct.go

+ 10 - 0
client/engineclient.go

@@ -317,12 +317,22 @@ func scanControllers(ctrldir string) ([]XmlController, error){
 			fmt.Println("controller xml file " + ctrlfile + " does not exist")
 			return controllers, err
 		}
+
+		ctrlfile = strings.Replace(ctrlfile, "\\", "/", -1)
+		arr := strings.Split(ctrlfile, "/")
+
 		bytess, _ := ioutil.ReadFile(ctrlfile)
 		err = xml.Unmarshal(bytess, &ctrl)
 		if err != nil {
 			fmt.Println("xml.Unmarshal(bytess, &app) error " + err.Error())
 			return controllers, err
 		}
+
+		// get sub dir name
+		if arr[len(arr) - 2] != "controllers"{
+			// if sub dir is not controllers, set the dir attr
+			ctrl.Dir = arr[len(arr) - 2]
+		}
 		controllers = append(controllers, ctrl)
 	}
 	return controllers, nil

+ 7 - 6
client/struct.go

@@ -19,12 +19,13 @@ type XmlControllers struct {
 }
 
 type XmlController struct {
-	Name string `xml:"name,attr"`
-	Desc         string `xml:"desc,attr"`
-	SkipLogin    bool `xml:"skip_login,attr"`
-	Apis []XmlApi `xml:"api"`
-	ApplicationName string `xml:"-"`
-	PackageName string `xml:"-"`
+	Name            string   `xml:"name,attr"`
+	Desc            string   `xml:"desc,attr"`
+	Dir             string   `xml:"dir,attr"`
+	SkipLogin       bool     `xml:"skip_login,attr"`
+	Apis            []XmlApi `xml:"api"`
+	ApplicationName string   `xml:"-"`
+	PackageName     string   `xml:"-"`
 }
 
 type XmlApi struct {