|
@@ -11,6 +11,7 @@ import (
|
|
"regexp"
|
|
"regexp"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
|
|
+ "sync"
|
|
)
|
|
)
|
|
|
|
|
|
// ConversionMoney 金额格式化
|
|
// ConversionMoney 金额格式化
|
|
@@ -51,18 +52,41 @@ func ConversionMoney(i_money interface{}) string {
|
|
|
|
|
|
var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
|
|
var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
|
|
|
|
|
|
-func GetCommonRenderPatch(agent, value string) string {
|
|
|
|
|
|
+func GetCommonRenderPath(agent, value string) string {
|
|
if IsMobile(agent) {
|
|
if IsMobile(agent) {
|
|
return fmt.Sprintf("mobile/%s", value)
|
|
return fmt.Sprintf("mobile/%s", value)
|
|
}
|
|
}
|
|
return fmt.Sprintf("pc/%s", value)
|
|
return fmt.Sprintf("pc/%s", value)
|
|
}
|
|
}
|
|
|
|
|
|
-func GetCommonRenderPatchs(agent, value string) string {
|
|
|
|
|
|
+var getCacheRenderFilePaths = getRenderFilePaths()
|
|
|
|
+
|
|
|
|
+// GetCommonRenderPaths 当移动端未找到模版,渲染pc模版
|
|
|
|
+func GetCommonRenderPaths(agent, filename string) []string {
|
|
if IsMobile(agent) {
|
|
if IsMobile(agent) {
|
|
- return fmt.Sprintf("mobile/%s", value)
|
|
|
|
|
|
+ return []string{fmt.Sprintf("mobile/%s", filename), fmt.Sprintf("pc/%s", filename)}
|
|
|
|
+ }
|
|
|
|
+ return []string{fmt.Sprintf("pc/%s", filename)}
|
|
|
|
+}
|
|
|
|
+func GetCommonRenderCachePaths(agent, value string) []string {
|
|
|
|
+ return getCacheRenderFilePaths(IsMobile(agent), value)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getRenderFilePaths() func(bool, string) []string {
|
|
|
|
+ cacheMap := map[string]map[bool][]string{}
|
|
|
|
+ lock := sync.Mutex{}
|
|
|
|
+ return func(isMobile bool, filename string) []string {
|
|
|
|
+ lock.Lock()
|
|
|
|
+ defer lock.Unlock()
|
|
|
|
+ if m, ok := cacheMap[filename]; ok && len(m) == 2 {
|
|
|
|
+ return m[isMobile]
|
|
|
|
+ }
|
|
|
|
+ cacheMap[filename] = map[bool][]string{
|
|
|
|
+ true: {fmt.Sprintf("mobile/%s", filename), fmt.Sprintf("pc/%s", filename)},
|
|
|
|
+ false: {fmt.Sprintf("pc/%s", filename)},
|
|
|
|
+ }
|
|
|
|
+ return cacheMap[filename][isMobile]
|
|
}
|
|
}
|
|
- return fmt.Sprintf("pc/%s", value)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func IsMobile(agent string) bool {
|
|
func IsMobile(agent string) bool {
|