Ver código fonte

版本号配置

wangshan 4 anos atrás
pai
commit
6fbde0029f
3 arquivos alterados com 77 adições e 0 exclusões
  1. 7 0
      src/jfw/tag/msg.go
  2. 64 0
      src/jfw/tag/tag.go
  3. 6 0
      src/seo.json

+ 7 - 0
src/jfw/tag/msg.go

@@ -56,6 +56,13 @@ func readproperty(mtype, key string) string {
 		if key == "version" && config.Seoconfig_Version != "" {
 			return config.Seoconfig_Version
 		}
+		if strings.HasSuffix(key, "_v") {
+			avk := applyVersion[key]
+			if avk != "" {
+				return avk
+			}
+			return config.Seoconfig_Version
+		}
 		tmp := util.GetPropertie(key, config.Seoconfig)
 		if tmp == nil {
 			return ""

+ 64 - 0
src/jfw/tag/tag.go

@@ -2,10 +2,74 @@ package tag
 
 import (
 	"jfw/config"
+	"log"
 	"qfw/util"
+	"strings"
+	"time"
+
+	"github.com/fsnotify/fsnotify"
 )
 
+var applyVersion = map[string]string{}
+var applyAction = map[string]int64{}
+var applyTime int64 = 5
+
 //自定义标签支持,读取配置文件
 func init() {
+	//应用版本号
+	seoConfigInit()
+	//监控目录
+	go watchDir("./seo.json")
+}
+
+//
+func seoConfigInit() {
 	util.ReadConfig("./seo.json", &config.Seoconfig)
+	if config.Seoconfig["applyVersion"] != nil {
+		applyV := util.ObjArrToStringArr(config.Seoconfig["applyVersion"].([]interface{}))
+		if len(applyV) > 0 {
+			for _, v := range applyV {
+				if len(strings.Split(v, ":")) > 0 {
+					name := strings.Split(v, ":")[0]
+					version := strings.Split(v, ":")[1]
+					applyVersion[name] = version
+				}
+			}
+		}
+	}
+}
+
+//监控目录
+func watchDir(dir string) {
+	watch, err := fsnotify.NewWatcher()
+	if err != nil {
+		log.Println("watch new err", err)
+	}
+	defer watch.Close()
+	err = watch.Add(dir)
+	if err != nil {
+		log.Println("watch add err", err)
+	}
+	for {
+		select {
+		case ev := <-watch.Events:
+			{
+				if ev.Op&fsnotify.Write == fsnotify.Write {
+					now := time.Now().Unix()
+					if applyAction[ev.Name] != 0 && now-applyAction[ev.Name] < applyTime {
+						continue
+					}
+					log.Println("修改文件 : ", ev.Name)
+					applyAction[ev.Name] = now
+					//更新应用版本号
+					seoConfigInit()
+				}
+			}
+		case err := <-watch.Errors:
+			{
+				log.Println("watch error : ", err.Error())
+				return
+			}
+		}
+	}
 }

+ 6 - 0
src/seo.json

@@ -13,6 +13,12 @@
         }
     },
     "version": "1413",
+    "applyVersion":[
+    	"docs_v:0001",
+		"points_v:0001",
+		"entniche_v:0001",
+		"coupon_v:0001"
+    ],
     "area": {
         "QG": {
             "NAME": "全国",