示例#1
0
文件: main.go 项目: Zerak/gonote
func WriteLog2(logInfo LiveLogModel, ipaddress string) {
	fmt.Printf("\nwriteLog2...\n")
	if logInfo.LiveId != "" && logInfo.LogContent != "" {
		if index := strings.Index(logInfo.LiveId, "?type="); index != -1 {
			logInfo.LiveId = common.SubString(logInfo.LiveId, 0, index)
		}
		logInfo.LiveId = strings.TrimPrefix(logInfo.LiveId, "liveid_")
		logInfo.Ip = ipaddress
		if strings.Contains(logInfo.LogContent, "[bR:") && strings.Contains(logInfo.LogContent, " k/s") {
			prefix := "bR:"
			brIdx := strings.Index(logInfo.LogContent, "bR:")
			ksidx := strings.Index(logInfo.LogContent, " k/s")
			str := common.SubString(logInfo.LogContent, brIdx+len(prefix), ksidx-brIdx-len(prefix))
			spd, _ := strconv.ParseFloat(str, 64)
			fmt.Printf("spd:%v\n", spd)

			logInfo.Tx = (int64)(spd * 1000)
			logInfo.Time = time.Now().UnixNano()
			//logModelChan <- logInfo
		} else {
		}

		fmt.Println(logInfo)
	}
}
示例#2
0
文件: main.go 项目: Zerak/gonote
func WriteLog(logInfo LiveLogModel, ipaddress string) {
	fmt.Printf("writeLog...\n")
	if logInfo.LiveId != "" && logInfo.LogContent != "" {
		if index := strings.Index(logInfo.LiveId, "?type="); index != -1 {
			logInfo.LiveId = common.SubString(logInfo.LiveId, 0, index)
		}
		logInfo.LiveId = strings.TrimPrefix(logInfo.LiveId, "liveid_")
		logInfo.Ip = ipaddress
		if strings.Contains(logInfo.LogContent, "[bR:") {
			prefix := "bR:"
			brIdx := strings.Index(logInfo.LogContent, "bR:")
			newStr := common.SubString(logInfo.LogContent, brIdx+len(prefix), len(logInfo.LogContent)-brIdx)
			numIdx := 0
			for i, v := range newStr {
				if v >= 48 && v <= 57 { // 0-9 assic 48-57
					continue
				}
				if v == 46 { // . assic 46
					continue
				}
				numIdx = i // 数字索引
				break
			}
			spdStr := common.SubString(newStr, 0, numIdx)
			var spd int64

			strTye := common.SubString(newStr, numIdx, len(logInfo.LogContent)-numIdx) // k/s... OR b/s...
			strTye = strings.TrimLeft(strTye, " ")
			if strTye[0] == 'b' {
				ss, _ := strconv.Atoi(spdStr)
				spd = (int64)(ss)
			} else if strTye[0] == 'k' {
				ss, _ := strconv.ParseFloat(spdStr, 64)
				spd = (int64)(ss * 1000)
			}

			fmt.Printf("type[%v] spd:%v\n", string(strTye[0]), spd)

			logInfo.Tx = spd
			logInfo.Time = time.Now().UnixNano()
			//logModelChan <- logInfo
		} else {
		}

		fmt.Println(logInfo)
	}
}