• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang geoip.GeoIP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/abh/geoip.GeoIP的典型用法代码示例。如果您正苦于以下问题:Golang GeoIP类的具体用法?Golang GeoIP怎么用?Golang GeoIP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了GeoIP类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: parseQueries

func parseQueries(queries <-chan *store.Query, geolocator *geoip.GeoIP) <-chan *store.ParsedQuery {
	parsedQueries := make(chan *store.ParsedQuery)
	go func() {
		for query := range queries {
			request, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(query.RawRequest)))
			if err != nil {
				log.Printf("error parsing result request: %v", err)
			}
			clientIp := request.Header.Get("X-Real-Ip")
			if clientIp == "" {
				clientIp = query.RemoteAddr
			}

			var parameters map[string]string
			if err := json.Unmarshal(query.ParametersJson, &parameters); err != nil {
				log.Printf("error parsing query parameters: %v", err)
			}

			parametersNullable := make(map[string]sql.NullString)
			for k, v := range parameters {
				parametersNullable[k] = sql.NullString{
					String: v,
					Valid:  true,
				}
			}

			host, _, err := net.SplitHostPort(clientIp)
			if err != nil {
				host = clientIp
			}

			country, _ := geolocator.GetCountry(host)

			parsedQueries <- &store.ParsedQuery{
				Query:          query.Id,
				MeasurementId:  parameters["measurementId"],
				Timestamp:      query.Timestamp,
				ClientIp:       net.ParseIP(host),
				ClientLocation: country,
				Substrate:      query.Substrate,
				Parameters:     parametersNullable,
			}
		}
		close(parsedQueries)
	}()
	return parsedQueries
}
开发者ID:a-jain,项目名称:encore,代码行数:47,代码来源:parser.go


示例3: parseResults

func parseResults(results <-chan *store.Result, geolocator *geoip.GeoIP) <-chan *store.ParsedResult {
	parsedResults := make(chan *store.ParsedResult)
	go func() {
		for result := range results {
			request, err := http.ReadRequest(bufio.NewReader(bytes.NewReader(result.RawRequest)))
			if err != nil {
				log.Printf("error parsing result request: %v", err)
			}
			measurementId := request.URL.Query().Get("cmh-id")
			outcome := request.URL.Query().Get("cmh-result")
			message := request.URL.Query().Get("cmh-message")
			userAgent := request.Header.Get("User-Agent")
			origin := request.Header.Get("Origin")
			referer := request.Header.Get("Referer")
			clientIp := request.Header.Get("X-Real-Ip")
			if clientIp == "" {
				clientIp = result.RemoteAddr
			}

			host, _, err := net.SplitHostPort(clientIp)
			if err != nil {
				host = clientIp
			}

			country, _ := geolocator.GetCountry(host)

			parsedResults <- &store.ParsedResult{
				Result:         result.Id,
				Timestamp:      result.Timestamp,
				MeasurementId:  measurementId,
				Outcome:        outcome,
				Message:        message,
				Origin:         origin,
				Referer:        referer,
				ClientIp:       net.ParseIP(host),
				ClientLocation: country,
				UserAgent:      userAgent,
			}
		}
		close(parsedResults)
	}()
	return parsedResults

}
开发者ID:a-jain,项目名称:encore,代码行数:44,代码来源:parser.go


示例4: test4

func test4(g geoip.GeoIP, ip string) {
	test(func(s string) string { return g.GetCountry(s) }, ip)
}
开发者ID:araddon,项目名称:geoip,代码行数:3,代码来源:geoip-demo.go


示例5: test4

func test4(g *geoip.GeoIP, ip string) {
	test(func(s string) (string, int) { return g.GetCountry(s) }, ip)
}
开发者ID:aziontech,项目名称:geoip,代码行数:3,代码来源:geoip-demo.go


示例6: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang leveldb.CloseAndDeleteDB函数代码示例发布时间:2022-05-24
下一篇:
Golang dns.RR_Header类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap