Skip to content

Commit

Permalink
go fmt after changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Nebel <nebel.sven@gmail.com>
  • Loading branch information
snebel29 committed Jul 13, 2021
1 parent 66c6db0 commit afc5301
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions plugin/geoip/city.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"

"github.com/coredns/coredns/plugin/metadata"

"github.com/oschwald/geoip2-golang"
)

Expand All @@ -14,45 +14,45 @@ const defaultLang = "en"
func (g GeoIP) setCityMetadata(ctx context.Context, data *geoip2.City) {
// Set labels for city, country and continent names.
cityName := data.City.Names[defaultLang]
metadata.SetValueFunc(ctx, pluginName + "/city/name", func() string {
metadata.SetValueFunc(ctx, pluginName+"/city/name", func() string {
return cityName
})
countryName := data.Country.Names[defaultLang]
metadata.SetValueFunc(ctx, pluginName + "/country/name", func() string {
metadata.SetValueFunc(ctx, pluginName+"/country/name", func() string {
return countryName
})
continentName := data.Continent.Names[defaultLang]
metadata.SetValueFunc(ctx, pluginName + "/continent/name", func() string {
metadata.SetValueFunc(ctx, pluginName+"/continent/name", func() string {
return continentName
})

countryCode := data.Country.IsoCode
metadata.SetValueFunc(ctx, pluginName + "/country/code", func() string {
metadata.SetValueFunc(ctx, pluginName+"/country/code", func() string {
return countryCode
})
isInEurope := strconv.FormatBool(data.Country.IsInEuropeanUnion)
metadata.SetValueFunc(ctx, pluginName + "/country/is_in_european_union", func() string {
metadata.SetValueFunc(ctx, pluginName+"/country/is_in_european_union", func() string {
return isInEurope
})
continentCode := data.Continent.Code
metadata.SetValueFunc(ctx, pluginName + "/continent/code", func() string {
metadata.SetValueFunc(ctx, pluginName+"/continent/code", func() string {
return continentCode
})

latitude := strconv.FormatFloat(float64(data.Location.Latitude), 'f', -1, 64)
metadata.SetValueFunc(ctx, pluginName + "/latitude", func() string {
metadata.SetValueFunc(ctx, pluginName+"/latitude", func() string {
return latitude
})
longitude := strconv.FormatFloat(float64(data.Location.Longitude), 'f', -1, 64)
metadata.SetValueFunc(ctx, pluginName + "/longitude", func() string {
metadata.SetValueFunc(ctx, pluginName+"/longitude", func() string {
return longitude
})
timeZone := data.Location.TimeZone
metadata.SetValueFunc(ctx, pluginName + "/timezone", func() string {
metadata.SetValueFunc(ctx, pluginName+"/timezone", func() string {
return timeZone
})
postalCode := data.Postal.Code
metadata.SetValueFunc(ctx, pluginName + "/postalcode", func() string {
metadata.SetValueFunc(ctx, pluginName+"/postalcode", func() string {
return postalCode
})
}
6 changes: 3 additions & 3 deletions plugin/geoip/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net"
"path/filepath"

clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"

"github.com/miekg/dns"
Expand All @@ -20,8 +20,8 @@ var log = clog.NewWithPlugin(pluginName)
// GeoIP is a plugin that add geo location data to the request context by looking up a maxmind
// geoIP2 database, and which data can be later consumed by other middlewares.
type GeoIP struct {
Next plugin.Handler
db db
Next plugin.Handler
db db
}

type db struct {
Expand Down
10 changes: 5 additions & 5 deletions plugin/geoip/geoip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"testing"

"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/plugin/test"
"github.com/coredns/coredns/request"
"github.com/coredns/coredns/plugin/metadata"
)

func TestMetadata(t *testing.T) {
Expand All @@ -23,10 +23,10 @@ func TestMetadata(t *testing.T) {
{cityDBPath, "geoip/country/name", "United Kingdom"},
// is_in_european_union is set to true only to work around bool zero value, and test is really being set.
{cityDBPath, "geoip/country/is_in_european_union", "true"},

{cityDBPath, "geoip/continent/code", "EU"},
{cityDBPath, "geoip/continent/name", "Europe"},

{cityDBPath, "geoip/latitude", "52.2242"},
{cityDBPath, "geoip/longitude", "0.1315"},
{cityDBPath, "geoip/timezone", "Europe/London"},
Expand All @@ -46,15 +46,15 @@ func TestMetadata(t *testing.T) {
if fmt.Sprintf("%p", ctx) != fmt.Sprintf("%p", rCtx) {
t.Errorf("Test %d: returned context is expected to be the same one passed in the Metadata function", i)
}

fn := metadata.ValueFunc(ctx, _test.label)
if fn == nil {
t.Errorf("Test %d: label %q not set in metadata plugin context", i, _test.label)
continue
}
value := fn()
if value != _test.expectedValue {
t.Errorf("Test %d: expected value for label %q should be %q, got %q instead",
t.Errorf("Test %d: expected value for label %q should be %q, got %q instead",
i, _test.label, _test.expectedValue, value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions plugin/geoip/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
)

var (
fixturesDir = "./testdata"
cityDBPath = filepath.Join(fixturesDir, "GeoLite2-City.mmdb")
unknownDBPath = filepath.Join(fixturesDir, "GeoLite2-UnknownDbType.mmdb")
fixturesDir = "./testdata"
cityDBPath = filepath.Join(fixturesDir, "GeoLite2-City.mmdb")
unknownDBPath = filepath.Join(fixturesDir, "GeoLite2-UnknownDbType.mmdb")
)

func TestProbingIP(t *testing.T) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestGeoIPParse(t *testing.T) {
}{
// Valid
{false, fmt.Sprintf("%s %s\n", pluginName, cityDBPath), "", city},

// Invalid
{true, pluginName, "Wrong argument count", 0},
{true, fmt.Sprintf("%s %s {\n\tlanguages en fr es zh-CN\n}\n", pluginName, cityDBPath), "unexpected config block", 0},
Expand Down

0 comments on commit afc5301

Please sign in to comment.