A tiny Go web app that display sample information from the visitor (IP, location, browser HTTP headers ...): whoami (Development version: dev). It is a rewriting of one of my previous mini project (whoami-python.)
This app is strongly inspired by ifconfig.me
- Golang 1.21 or higher
Prebuilt binaries can be downloaded from the GitHub Releases section, or using a Docker image from the Github Container Registry. See here
You need a working go toolchain (It has been developped and tested with go 1.21 and should work with go >= 1.21). Refer to the official documentation for more information (or from your Linux/Mac/Windows distribution documentation to install it from your favorite package manager).
# Clone this repository
git clone https://github.com/lescactus/whoami-go.git && cd whoami-go/
# Build from sources. Use the '-o' flag to change the compiled binary name
go build
# Default compiled binary is whoami-go
# You can optionnaly move it somewhere in your $PATH to access it shell wide
./whoami-go
If you don't have go installed but have docker, run the following command to build inside a docker container:
# Build from sources inside a docker container. Use the '-o' flag to change the compiled binary name
# Warning: the compiled binary belongs to root:root
docker run --rm -it -v "$PWD":/app -w /app golang:1.20 go build -buildvcs=false
# Default compiled binary is whoami-go
# You can optionnaly move it somewhere in your $PATH to access it shell wide
./whoami-go
The server is accessible at http://127.0.0.1:8080
whoami-go
comes with a Dockerfile
. To build the image:
docker build -t whoami-go .
docker run -d -p 8080:8080 --restart="always" --name whoami-go whoami-go
The server is accessible at http://127.0.0.1:8080
docker run -d -p 8080:8080 --restart="always" --name whoami-go ghcr.io/lescactus/whoami-go
The server is accessible at http://127.0.0.1:8080
docker compose up
The server is accessible at http://127.0.0.1:8080
-
GET /
display informations from the browser: http headers, public IP, geo locations informations (such as country name, city name, etc ...) and a map -
GET /index
display informations from the browser: http headers, public IP, geo locations informations (such as country name, city name, etc ...) and a map -
GET /ip
display the public ip of the browser -
GET /port
display the remote port of the browser -
GET /lang
display the language of the browser (Accept-Language
) -
GET /ua
display the user agent of the browser (User-Agent
) -
GET /raw/go
display all the http headers the browser send in a golang fashion format -
GET /raw/json
display all the http headers the browser send in json -
GET /raw/yaml
display all the http headers the browser send in yaml -
GET /metrics
display prometheus metrics if enabled (see configuration below)
whoami-go
is a 12-factor app using Viper as a configuration manager. It can read configuration either from environment variables or from a key/value .env
file. This .env
file represents system environment variables on the machine. This change was made with the ease-of-use with Docker in mind.
-
APP_ADDR
(default value::8080
) -
APP_ENV
(default value:local
). If set to anything other thanproduction
, run thepprof
server at/debug/pprof/
-
APP_CONFIG_NAME
(default.env
) -
APP_CONFIG_PATH
(default.
) -
SERVER_FIBER_PREFORK
(default value:false
) -
SERVER_FIBER_READ_TIMEOUT
(default value:10s
) -
SERVER_FIBER_WRITE_TIMEOUT
(default value:10s
) -
SERVER_FIBER_IDLE_TIMEOUT
(default value:75s
) -
SERVER_FIBER_ENABLE_TRUSTED_PROXY_CHECK
(default value:true
) -
SERVER_FIBER_PROXY_HEADER
(default value:X-Forwarded-For
) -
SERVER_FIBER_TRUSTED_PROXIES
(default value:169.254.8.129
) -
SERVER_FIBER_DISABLE_KEEPALIVE
(default value:false
) -
VIEWS_TEMPLATE_DIRECTORY
(default value:./views/template
) -
VIEWS_TEMPLATE_EXTENSIONS
(default value:.html
) -
VIEWS_STATIC_DIRECTORY
(default value:./views/static
) -
MIDDLEWARE_RECOVER_ENABLE_STACK_TRACE
(default value:true
) -
HTTP_CLIENT_TIMEOUT
(default value:5s
) -
GEOLOCATION_API
(default value:freegeoip
). Define which IP GeoLocation API to use (https://freegeoip.app/, https://ip-api.com/). Valid values arefreegeoip
oripapi
-
LOGGER_TYPE
(default value:gofiber
). Define which logger to use. Valid values aregofiber
(default logger) orzap
-
LOGGER_ZAP_LOG_LEVEL
(default value:info
). Only usable whenLOGGER_TYPE=zap
-
LOGGER_ZAP_DEVELOPMENT_MODE
(default value:false
). Only usable whenLOGGER_TYPE=zap
-
LOGGER_ZAP_DISABLE_CALLER
(default value:true
). Only usable whenLOGGER_TYPE=zap
-
LOGGER_ZAP_DISABLE_STACK_TRACE
(default value:true
). Only usable whenLOGGER_TYPE=zap
-
LOGGER_ZAP_ENCODING
(default value:json
). Valid values are:json
orconsole
. Only usable whenLOGGER_TYPE=zap
-
MIDDLEWARE_PROMETHEUS_ENABLED
(default value:true
) -
MIDDLEWARE_PROMETHEUS_METRICS_PATH
(default value:/metrics
) Only usable whenMIDDLEWARE_PROMETHEUS_ENABLED=true