Code Monkey home page Code Monkey logo

golang-ip2location's Introduction

golang-ip2location

For self hosted, ready to use RESTful API microservice for converting IP to location such a City, Countryand Region. Free lite database version of ip2location.com is used. Please donwload your own database file from ip2location.com. You can also use db-update.sh script in the root directory for automatically refreshing database from ip2location.com with your own token. You can download databsae here https://lite.ip2location.com/database-download

Docker image: https://hub.docker.com/r/vladimirok5959/golang-ip2location

Usage

Usage of ./ip2location:
  -access_log_file string
    Or ENV_ACCESS_LOG_FILE: Access log file
  -data_dir string
    Or ENV_DATA_DIR: Application data directory
  -db_update_time int
    Or ENV_DB_UPDATE_TIME: Delay in minutes between database reloading (default 60)
  -deployment string
    Or ENV_DEPLOYMENT: Deployment type (default "development")
  -error_log_file string
    Or ENV_ERROR_LOG_FILE: Error log file
  -host string
    Or ENV_HOST: Web server IP (default "127.0.0.1")
  -limit_requests int
    Or ENV_LIMIT_REQUESTS: Requests per second per one IP (default 5)
  -port string
    Or ENV_PORT: Web server port (default "8080")
  -web_url string
    Or ENV_WEB_URL: Web server home URL (default "http://localhost:8080/")

API endpoint

Only one: http://localhost:8080/api/v1/ip2location/8.8.8.8

HTTP/1.1 200 OK
Content-Type: application/json
Date: Thu, 12 Oct 2022 20:45:48 GMT
Content-Length: 107
{
    "City": "Mountain View",
    "CountryLong": "United States of America",
    "CountryShort": "US",
    "Region": "California"
}

DB auto update

Right now, application is not designed for automatically refreshing database. Application just load pre-downloaded dabase file, load it on startup and reread database every 60 minutes (interval can be changed by ENV_DB_UPDATE_TIME variable), but database file need to update manually. So you must care about refreshing databse by yourself by using for example crontab and included db-update.sh script. Example for crontab file:

0    2    1    *    *    root    /var/ip2location/db-update.sh "your token" "/var/ip2location/data/IP2LOCATION-LITE-DB3.BIN" > /dev/null 2>&1

Script takes two parameters, first - your database token from ip2location.com, and second - database file. In this example script will automatically refresh database every month at 2 AM, once at month. It's enough for free lite database version. Script will not damage database file on fail

Running docker container

docker run -d \
    --network host \
    --restart=always \
    --name my-container-name \
    -e ENV_DATA_DIR="/app/data" \
    -e ENV_DB_UPDATE_TIME="60" \
    -e ENV_DEPLOYMENT="deployment" \
    -e ENV_HOST="127.0.0.1" \
    -e ENV_PORT="8080" \
    -e ENV_WEB_URL="http://localhost:8080/" \
    -v /etc/timezone:/etc/timezone:ro \
    -v /var/ip2location/data:/app/data \
    vladimirok5959/golang-ip2location:latest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.