Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1.01 KB

README.md

File metadata and controls

45 lines (34 loc) · 1.01 KB

goip

Godoc Build Status MIT License

Tiny utility to deal with IP

How to install

go get github.com/shamsher31/goip

How to use

package main

import (
  "fmt"
  "github.com/shamsher31/goip"
  "net/http"
)

func reqHandler(w http.ResponseWriter, req *http.Request) {
  // Returns 1.187.109.235, nil
  fmt.Println(ip.Remote(req))
}

func main() {
  // Returns 10.102.29.20, nil
  fmt.Println(ip.Local())

  // Run simple server to test
  http.HandleFunc("/", reqHandler)
  http.ListenAndServe(":8090", nil)
}

Why

This package will be useful when you write application which require you to deal with local or remote IP of the requested host.

License

MIT © Shamsher Ansari