Ejemplo n.º 1
0
func parseLocation(c *models.Context) *string {
	record, err := helper.MustGetGeoIPDB().City(c.Client.IP)
	if err != nil {
		runner.MustGetLogger().Error("Err while parsing ip, err :%s", err.Error())

	} else {
		city := record.City.Names["en"]
		country := record.Country.Names["en"]
		if city != "" {
			location := fmt.Sprintf("%s, %s", city, country)
			return &location
		} else {
			location := fmt.Sprintf("%s", country)
			return &location
		}
	}
	return nil
}
Ejemplo n.º 2
0
// Location returns the current approximate location of the requester
func Location(u *url.URL, h http.Header, c *models.Context) (int, http.Header, interface{}, error) {
	record, err := helper.MustGetGeoIPDB().City(c.Client.IP)
	if err != nil {
		return response.NewBadRequest(err)
	}

	var location string
	city := record.City.Names[en]
	country := record.Country.Names[en]

	if city != "" {
		location = fmt.Sprintf("%s, %s", city, country)
	} else {
		location = fmt.Sprintf("%s", country)
	}

	return response.NewOK(
		map[string]interface{}{
			"location": location,
		},
	)
}