當前位置: 首頁>>代碼示例>>Golang>>正文


Golang GeoIP.GetRecord方法代碼示例

本文整理匯總了Golang中github.com/abh/geoip.GeoIP.GetRecord方法的典型用法代碼示例。如果您正苦於以下問題:Golang GeoIP.GetRecord方法的具體用法?Golang GeoIP.GetRecord怎麽用?Golang GeoIP.GetRecord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/abh/geoip.GeoIP的用法示例。


在下文中一共展示了GeoIP.GetRecord方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mapPairToCSV

func mapPairToCSV(colHeader string, inMap PairList, fh *os.File, geo *geoip.GeoIP) int {

	nb, err := fh.WriteString(colHeader + "\n")
	check(err)
	totalBytes := nb
	i := 0

	for _, v1 := range inMap {

		matches := regexp.MustCompile(`([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)`).FindStringSubmatch(v1.Key)
		if len(matches) >= 1 && geo != nil {
			record := geo.GetRecord(v1.Key)
			if record != nil {
				nb, err = fh.WriteString(v1.Key + csvd + strconv.Itoa(v1.Value) + csvd + record.City + csvd + record.CountryName + "\n")
			}
		} else {
			nb, err = fh.WriteString(v1.Key + csvd + strconv.Itoa(v1.Value) + "\n")
		}
		check(err)
		totalBytes += nb
		i++
	}
	fh.Sync()
	return totalBytes
}
開發者ID:hartfordfive,項目名稱:gotools,代碼行數:25,代碼來源:parselog.go

示例2: Transform

func (event *SnowplowEvent) Transform(request []byte, geo *geoip.GeoIP) error {
	event.Body = request

	normString, err := strconv.Unquote(`"` + string(request) + `"`)
	if err != nil {
		return err
	}

	normString = strings.Replace(normString, "\" ", "", -1)

	snowplowRequest := &SnowplowRequest{}
	err = json.Unmarshal([]byte(normString), snowplowRequest)
	if err != nil {
		return err
	}

	// Binding first level nginx fields
	checkStringForNull(snowplowRequest.IPAddress, &event.UserIP)
	event.CollectorTstamp = time.Now()
	// checkStringForNull(snowplowRequest.Referer, &event.PageReferrer)
	checkStringForNull(snowplowRequest.Useragent, &event.Useragent)

	// Binding snowplow data
	snowplowData := snowplowRequest.RequestBody.Data[0]

	// Bind string values
	checkStringForNull(snowplowData.Event, &event.Event)
	checkStringForNull(snowplowData.PageURL, &event.PageURL)
	checkStringForNull(snowplowData.PageTtile, &event.PageTtile)
	checkStringForNull(snowplowData.PageReferrer, &event.PageReferrer)
	checkStringForNull(snowplowData.VTracker, &event.VTracker)
	checkStringForNull(snowplowData.Aid, &event.Aid)
	checkStringForNull(snowplowData.Platform, &event.Platform)
	checkStringForNull(snowplowData.OsTimezone, &event.OsTimezone)
	checkStringForNull(snowplowData.BrLang, &event.BrLang)
	checkStringForNull(snowplowData.DocCharset, &event.DocCharset)
	checkStringForNull(snowplowData.EventID, &event.EventID)
	checkStringForNull(snowplowData.DomainUserID, &event.DomainUserID)
	checkStringForNull(snowplowData.UserFingerprint, &event.UserFingerprint)
	checkStringForNull(snowplowData.SeCategory, &event.SeCategory)
	checkStringForNull(snowplowData.SeAction, &event.SeAction)
	checkStringForNull(snowplowData.SeLabel, &event.SeLabel)
	checkStringForNull(snowplowData.SeProperty, &event.SeProperty)
	checkFloatForNull(snowplowData.SeValue, &event.SeValue)

	// Bind integer values
	checkIntForNull(snowplowData.BrColorDepth, &event.BrColorDepth)
	checkIntForNull(snowplowData.VisitNum, &event.VisitNum)
	checkIntForNull(snowplowData.UserID, &event.UserID)

	// Bind boolean values
	event.BrPDF, _ = strconv.ParseBool(snowplowData.BrPDF)
	event.BrQT, _ = strconv.ParseBool(snowplowData.BrQT)
	event.BrRealPlayer, _ = strconv.ParseBool(snowplowData.BrRealPlayer)
	event.BrWMA, _ = strconv.ParseBool(snowplowData.BrWMA)
	event.BrDir, _ = strconv.ParseBool(snowplowData.BrDir)
	event.BrFlash, _ = strconv.ParseBool(snowplowData.BrFlash)
	event.BrJava, _ = strconv.ParseBool(snowplowData.BrJava)
	event.BrGears, _ = strconv.ParseBool(snowplowData.BrGears)
	event.BrAg, _ = strconv.ParseBool(snowplowData.BrAg)
	event.BrCookies, _ = strconv.ParseBool(snowplowData.BrCookies)

	// Bind screen resolutions
	event.BrViewWidth = snowplowData.BrView.Width
	event.BrViewHeight = snowplowData.BrView.Height

	event.DvceScreenWidth = snowplowData.DvceScreen.Width
	event.DvceScreenHeight = snowplowData.DvceScreen.Height

	event.DocWidth = snowplowData.Doc.Width
	event.DocHeight = snowplowData.Doc.Width

	// Bind time values
	event.DvceTstamp = snowplowData.DvceTstamp.Time

	// Bind Geo values
	geoIPRecord := geo.GetRecord(snowplowRequest.IPAddress)
	if geoIPRecord != nil {
		checkStringForNull(geoIPRecord.CountryName, &event.GeoCountry)
		checkStringForNull(geoIPRecord.Region, &event.GeoRegion)
		checkStringForNull(geoIPRecord.City, &event.GeoCity)
		checkStringForNull(geoIPRecord.PostalCode, &event.GeoZipcode)
		event.GeoLatitude = geoIPRecord.Latitude
		event.GeoLongtitude = geoIPRecord.Longitude
		checkStringForNull(geoIPRecord.Region, &event.GeoRegionName)
	}

	// Bind useragent values

	ua := user_agent.New(snowplowRequest.Useragent)
	event.DvceIsMobile = ua.Mobile()

	checkStringForNull(ua.OS(), &event.OsName)
	checkStringForNull(ua.Platform(), &event.DvceType)

	name, version := ua.Engine()
	checkStringForNull(name+version, &event.BrRndrNgn)

	name, version = ua.Browser()
	checkStringForNull(name, &event.BrName)
//.........這裏部分代碼省略.........
開發者ID:Qlean,項目名稱:silvia,代碼行數:101,代碼來源:snowplow.go


注:本文中的github.com/abh/geoip.GeoIP.GetRecord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。