Documentation
¶
Overview ¶
package database provides tools for enriching IP addresses from enrichment databases.
Example (IP2Location) ¶
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/brexhq/substation/internal/ip/database"
)
func main() {
// create IP2Location container, open database, and close database when function returns
ip2loc := database.IP2Location{
Database: "location://path/to/ip2location.bin",
}
if err := ip2loc.Open(context.TODO()); err != nil {
// handle error
panic(err)
}
defer ip2loc.Close()
// query database
addr := "8.8.8.8"
record, err := ip2loc.Get(addr)
if err != nil {
// handle error
panic(err)
}
// marshal to JSON for printing
res, _ := json.Marshal(record)
fmt.Println(string(res))
}
Example (MaxMindCity) ¶
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/brexhq/substation/internal/ip/database"
)
func main() {
// create MaxMind City container, open database, and close database when function returns
mm := database.MaxMindCity{
Database: "location://path/to/maxmind.mmdb",
}
if err := mm.Open(context.TODO()); err != nil {
// handle error
panic(err)
}
defer mm.Close()
// query database
addr := "8.8.8.8"
record, err := mm.Get(addr)
if err != nil {
// handle error
panic(err)
}
// marshal to JSON for printing
res, _ := json.Marshal(record)
fmt.Println(string(res))
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IP2Location ¶
type IP2Location struct {
Database string `json:"database"`
// contains filtered or unexported fields
}
IP2Location provides read access to an IP2Location binary database.
func (*IP2Location) Get ¶
func (d *IP2Location) Get(addr string) (*ip.EnrichmentRecord, error)
Get queries the database and returns an aggregated database record containing enrichment information.
func (*IP2Location) IsEnabled ¶
func (d *IP2Location) IsEnabled() bool
IsEnabled returns true if the database is open and ready for use.
type MaxMindASN ¶
type MaxMindASN struct {
Database string `json:"database"`
Language string `json:"language"`
// contains filtered or unexported fields
}
MaxMindASN provides read access to MaxMind ASN database.
func (*MaxMindASN) Get ¶
func (d *MaxMindASN) Get(addr string) (*ip.EnrichmentRecord, error)
Get queries the database and returns an aggregated database record containing enrichment information.
func (*MaxMindASN) IsEnabled ¶
func (d *MaxMindASN) IsEnabled() bool
IsEnabled returns true if the database is open and ready for use.
func (*MaxMindASN) Open ¶
func (d *MaxMindASN) Open(ctx context.Context) error
Open retrieves the database and opens it for querying. The location of the database can be either a path on local disk, an HTTP(S) URL, or an AWS S3 URL. MaxMind language support is provided by calling GetMaxMindLanguage to retrieve a user-configured language.
type MaxMindCity ¶
type MaxMindCity struct {
Database string `json:"database"`
Language string `json:"language"`
// contains filtered or unexported fields
}
MaxMindCity provides read access to a MaxMind City database.
func (*MaxMindCity) Get ¶
func (d *MaxMindCity) Get(addr string) (*ip.EnrichmentRecord, error)
Get queries the database and returns an aggregated database record containing enrichment information.
func (*MaxMindCity) IsEnabled ¶
func (d *MaxMindCity) IsEnabled() bool
IsEnabled returns true if the database is open and ready for use.
type OpenCloser ¶
OpenCloser provides tools for opening, closing, and getting values from IP address enrichment databases.