ip2country

package module
v0.0.0-...-88e0f02 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2018 License: MIT Imports: 6 Imported by: 0

README

Build Status Coverage Status Go Report Card
ip2country is a golang package to find out IP's origin country. It uses db-ip.com's csv file to provide answers.

Install

go get -u github.com/mostafa-asg/ip2country

Usage

package main

import (
   "github.com/mostafa-asg/ip2country"
)

func main() {
   ip2country.Load( PATH_TO_DB-IP.COM'S CSV FILE )
   println(ip2country.GetCountry("2.179.6.12"))
   println(ip2country.GetCountry("172.217.18.14"))
   println(ip2country.GetCountry("217.160.123.58"))
}

Tips : Load method should be called once.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidIPv4 = errors.New("Invalid IPv4 address")

ErrInvalidIPv4 when invalid ip address provided

View Source
var ErrInvalidLine = errors.New("Invalid line structure")

ErrInvalidLine when csv line is invalid

Functions

func GetCountry

func GetCountry(ip string) string

GetCountry returns the country which ip blongs to

func GetCountryMulti

func GetCountryMulti(ips ...string) []string

GetCountryMulti is a batch version of GetCountry function It allows you to pass many ip addresses as input, and will return countries as output the first index of slice is the answer for the first input , the second index for the second input and so on

func Load

func Load(filepath string) error

Load db-ip.com csv file It must be called only once

Types

This section is empty.

Jump to

Keyboard shortcuts

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