DengBiao před 1 rokem
rodič
revize
9b1db712b1
2 změnil soubory, kde provedl 19 přidání a 9 odebrání
  1. +11
    -0
      app/utils/file.go
  2. +8
    -9
      consume/zhios_user_visit_ip_address_consume.go

+ 11
- 0
app/utils/file.go Zobrazit soubor

@@ -1,11 +1,22 @@
package utils

import (
"os"
"path"
"strings"
"time"
)

// 获取文件后缀
func FileExt(fname string) string {
return strings.ToLower(strings.TrimLeft(path.Ext(fname), "."))
}

func FilePutContents(fileName string, content string) {
fd, _ := os.OpenFile("./tmp/"+fileName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
fd_time := time.Now().Format("2006-01-02 15:04:05")
fd_content := strings.Join([]string{"[", fd_time, "] ", content, "\n"}, "")
buf := []byte(fd_content)
fd.Write(buf)
fd.Close()
}

+ 8
- 9
consume/zhios_user_visit_ip_address_consume.go Zobrazit soubor

@@ -73,13 +73,12 @@ func handleUserVisitIpAddress(msg []byte) error {
cacheKeyForUrl := fmt.Sprintf(md.ZhiOsMasterIdForUrlHashMapCacheKey)
get, _ := cache.HGetString(cacheKeyForUrl, msgStruct.Url)
if get == "" {
var domainType string
if msgStruct.Pvd == "app" || msgStruct.Pvd == "applet" {
domainType = "api"
} else {
domainType = "wap"
}
msgStruct.MasterId = GetWebSiteDomainMasterId(domainType, msgStruct.Url)
msgStruct.MasterId = GetWebSiteDomainMasterId(msgStruct.Url)
utils.FilePutContents("GetWebSiteDomainMasterId", utils.SerializeStr(msgStruct))
cache.HSet(cacheKeyForUrl, msgStruct.Url, msgStruct.MasterId)
cache.Expire(cacheKeyForUrl, md.ZhiOsUserVisitIpAddressHashMapCacheTime)
} else {
msgStruct.MasterId = get
}
}

@@ -147,9 +146,9 @@ func getIpAddress(Db *xorm.Engine, message md.ZhiOsUserVisitIpAddressMessage) (c
}

// 获取指定类型的域名对应的masterId:admin、wap、api
func GetWebSiteDomainMasterId(domainType string, host string) string {
func GetWebSiteDomainMasterId(host string) string {
obj := new(model.UserAppDomain)
has, err := db.Db.Where("domain=? and type=?", host, domainType).Get(obj)
has, err := db.Db.Where("domain=?", host).Get(obj)
if err != nil || !has {
return ""
}


Načítá se…
Zrušit
Uložit