ipgeolocation

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 10 Imported by: 0

README

IP geolocation

Importing data from csv files

You need to convert geolocation database *.csv files into *.db files that are used by this library.

package yourpackage

import "github.com/latolukasz/ipgeolocation"

func main() {
    err := ipgeolocation. Import("/path/to/csv/files/")
    if err != nil {
        panic(err)
    }
}

Searching

package yourpackage

import (
	"github.com/latolukasz/ipgeolocation"
	"fmt"
)

func main() {
    err := ipgeolocation.InitDB("/path/to/db/files/") // run it only once in your app
    if err != nil {
        panic(err)
    }
    record, err := ipgeolocation.Search("37.143.210.32")
    if err != nil {
        panic(err)
    }
    if record != nil {
        fmt.Printf("country: %s, city: %s", record.Country.Name, record.City)
    } else {
        fmt.Printf("not found")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(csvFilesDir string) error

func InitDB

func InitDB(dbDirectory string) error

Types

type Continent

type Continent struct {
	ISO  string
	Name string
}

type Country

type Country struct {
	Continent Continent
	ISO       string
	Name      string
	Currency  string
	Languages []string
}

type ImportArguments

type ImportArguments struct {
	DbDirectory string
}

type Result

type Result struct {
	Country  Country
	City     string
	Lat      float32
	Lon      float32
	Timezone string
}
func Search(ip string) (*Result, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL