Exemplo n.º 1
0
Arquivo: clouds.go Projeto: sqp/godock
// DetectLocation tries to detect your location from IP and get the matching code.
//
func (app *Applet) DetectLocation() {
	loc, e := iplocation.Get()
	if app.Log().Err(e, "autodetect location") {
		return
	}
	locations, e := weather.FindLocation(loc.City + ", " + loc.Country)
	if app.Log().Err(e, "FindLocation") || len(locations) == 0 {
		return
	}
	app.conf.LocationCode = locations[0].ID // do not save, just set live value.
	app.Log().Debug("autodetect location", locations[0].Name)
}
Exemplo n.º 2
0
func TestLocation(t *testing.T) {
	loc, e := iplocation.Get()

	if !assert.NoError(t, e, "iplocation.Get") &&
		!assert.NotNil(t, loc, "Get loc") {
		return
	}
	assert.NotEmpty(t, loc.Country, "loc.Country")
	assert.NotEmpty(t, loc.CountryCode, "loc.CountryCode")
	assert.NotEmpty(t, loc.Region, "loc.Region")
	assert.NotEmpty(t, loc.RegionName, "loc.RegionName")
	assert.NotEmpty(t, loc.City, "loc.City")
	assert.NotEmpty(t, loc.Lat, "loc.Lat")
	assert.NotEmpty(t, loc.Lon, "loc.Lon")
	assert.NotEmpty(t, loc.Timezone, "loc.Timezone")
	assert.NotEmpty(t, loc.ISP, "loc.ISP")
	assert.NotEmpty(t, loc.ORG, "loc.ORG")
}