本文整理汇总了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, ¶meters); 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
}
示例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
}
示例3: test4
func test4(g geoip.GeoIP, ip string) {
test(func(s string) string { return g.GetCountry(s) }, ip)
}
示例4: test4
func test4(g *geoip.GeoIP, ip string) {
test(func(s string) (string, int) { return g.GetCountry(s) }, ip)
}