mirror of
https://github.com/coredns/coredns.git
synced 2025-12-04 09:25:13 -05:00
plugin/geoip: Add ASN schema support (#7730)
Adds the ability to query ASN .mmdb databases, in addition to the existing City db functionality. Signed-off-by: Eric Case <eric.case@gmail.com>
This commit is contained in:
21
plugin/geoip/asn.go
Normal file
21
plugin/geoip/asn.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package geoip
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/coredns/coredns/plugin/metadata"
|
||||
|
||||
"github.com/oschwald/geoip2-golang"
|
||||
)
|
||||
|
||||
func (g GeoIP) setASNMetadata(ctx context.Context, data *geoip2.ASN) {
|
||||
asnNumber := strconv.FormatUint(uint64(data.AutonomousSystemNumber), 10)
|
||||
metadata.SetValueFunc(ctx, pluginName+"/asn/number", func() string {
|
||||
return asnNumber
|
||||
})
|
||||
asnOrg := data.AutonomousSystemOrganization
|
||||
metadata.SetValueFunc(ctx, pluginName+"/asn/org", func() string {
|
||||
return asnOrg
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user