https://github.com/akyriako/go-ifconfig-me
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.
https://github.com/akyriako/go-ifconfig-me
golang ifconfig-me public-ip-address what-is-my-ip
Last synced: 4 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/akyriako/go-ifconfig-me
- Owner: akyriako
- License: gpl-3.0
- Created: 2024-12-11T06:07:19.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-11T09:08:04.000Z (10 months ago)
- Last Synced: 2025-06-25T16:03:27.100Z (3 months ago)
- Topics: golang, ifconfig-me, public-ip-address, what-is-my-ip
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.

## How to use
Import the package as:
`import ifconfigme "github.com/akyriako/go-ifconfig-me"`
### Simple
```go
client := ifconfigme.NewClient()
response, err := client.Get()
if err != nil {
log.Fatal(err)
}log.Println(response)
```### With Options Pattern
```go
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
```go
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).