当前位置: 首页>>代码示例>>Golang>>正文


Golang GeoIP.GetCountry方法代码示例

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


在下文中一共展示了GeoIP.GetCountry方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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


注:本文中的github.com/abh/geoip.GeoIP.GetCountry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。