Skip to content

A small Golang package that helps you discover your public IP address by querying https://ifconfig.me/ and return the response as a Golang struct.

License

Notifications You must be signed in to change notification settings

akyriako/go-ifconfig-me

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ifconfig-me

Small Golang package that helps you discover your public IP address by querying https://ifconfig.me/ and return the response as a Golang struct.

image

How to use

Import the package as:

import ifconfigme "github.com/akyriako/go-ifconfig-me"

Simple

client := ifconfigme.NewClient()
response, err := client.Get()
if err != nil {
	log.Fatal(err)
}

log.Println(response)

With Options Pattern

client := ifconfigme.NewClient(
	ifconfigme.WithTimeout(350*time.Millisecond),
	ifconfigme.WithTransport(&http.Transport{}),
)
response, err := client.Get()
if err != nil {
	log.Fatal(err)
}

log.Println(response)

Response

type Response struct {
	IpAddr     string `json:"ip_addr"`
	RemoteHost string `json:"remote_host"`
	UserAgent  string `json:"user_agent"`
	Port       string `json:"port"`
	Language   string `json:"language"`
	Method     string `json:"method"`
	Encoding   string `json:"encoding"`
	Mime       string `json:"mime"`
	Via        string `json:"via"`
	Forwarded  string `json:"forwarded"`
}

The structure of the response is the following:

  • ip_addr: Your public IP address.
  • remote_host: Hostname associated with your IP, if resolvable otherwise returns unavailable.
  • user_agent: User agent string of the client making the request.
  • port: Port used by the client for the connection.
  • method: HTTP method used (in this case typically GET).
  • encoding: Encoding specified in the request.
  • mime: MIME type requested.
  • via: Proxy details if accessed through a proxy (empty if direct connection).
  • forwarded: Headers indicating forwarded IPs (empty if none).

About

A small Golang package that helps you discover your public IP address by querying https://ifconfig.me/ and return the response as a Golang struct.

Topics

Resources

License

Stars

Watchers

Forks

Languages