GithubHelp home page GithubHelp logo

cloudxtreme / go-ipify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rdegges/go-ipify

0.0 1.0 0.0 122 KB

The official client library for ipify: A Simple IP Address API.

License: The Unlicense

Go 100.00%

go-ipify's Introduction

go-ipify

The official client library for ipify: A Simple IP Address API.

GitHub License GitHub Stars GoDoc Build Status

Meta

Purpose

ipify is the best IP address lookup service on the internet. It's fast, simple, scalable, open source, and well-funded (by me!).

In short: if you need a way to pragmatically get your public IP address, ipify is the best possible choice!

This library will retrieve your public IP address from ipify's API service, and return it as a string. It can't get any simpler than that.

This library also has some other nice features you might care about:

  • If a request fails for any reason, it is re-attempted 3 times using an exponential backoff algorithm for maximum effectiveness.
  • This library handles errors properly, and usage examples below show you how to deal with errors in a foolproof way.
  • This library only makes API requests over HTTPS.

Installation

To install ipify, simply run:

$ go get github.com/rdegges/go-ipify

This will install the latest version of the library automatically.

Usage

Using this library is very simple. Here's a simple example:

package main

import (
    "fmt"
    "github.com/rdegges/go-ipify"
)

func main() {
    ip, err := ipify.GetIp()
    if err != nil {
        fmt.Println("Couldn't get my IP address:", err)
    } else {
        fmt.Println("My IP address is:", ip)
    }
}

Now, in regards to error handling, there are several ways this can fail:

  • The ipify service is down (not likely), or:
  • Your machine is unable to get the request to ipify because of a network error of some sort (DNS, no internet, etc.).

The library will output an informative error message in the event anything fails.

One thing to keep in mind: regardless of how you decide to handle errors, the ipify library will retry any failed requests 3 times before ever failing -- so if you do need to handle errors, just remember that retry logic has already been attempted.

Contributing

This project is only possible due to the amazing contributors who work on it!

If you'd like to improve this library, please send me a pull request! I'm happy to review and merge pull requests.

The standard contribution workflow should look something like this:

  • Fork this project on Github.
  • Make some changes in the master branch (this project is simple, so no need to complicate things).
  • Send a pull request when ready.

Also, if you're making changes, please write tests for your changes -- this project has a full test suite you can easily modify / test.

To run the test suite, you can use the go test command after forking this repository.

go-ipify's People

Contributors

rdegges avatar

Watchers

 avatar

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.