Skip to content

simple golang app to print request headers to stdout json logs

Notifications You must be signed in to change notification settings

nitesh8860/go-log-headers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-log-headers

go-log-headers is a straightforward Golang application designed to log HTTP request headers in JSON format to the standard output (stdout).

Overview

This application is a useful tool for inspecting incoming HTTP request headers. It can be run both directly on your local machine or within a Docker container.

Purpose

The primary purpose of this project is to test Ingress controller settings for pushing GeoIP headers into the logs. The following proxy headers are set by the Ingress controller:

proxySetHeaders:
  X-geoip-area-code: $geoip_area_code
  X-geoip-city-continent-code: $geoip_city_continent_code
  X-geoip-city-country-code: $geoip_city_country_code
  X-geoip-city-country-code3: $geoip_city_country_code3
  X-geoip-city-country-name: $geoip_city_country_name
  X-geoip-dma-code: $geoip_dma_code
  X-geoip-latitude: $geoip_latitude
  X-geoip-longitude: $geoip_longitude
  X-geoip-region: $geoip_region
  X-geoip-region-name: $geoip_region_name
  X-geoip-city: $geoip_city
  X-geoip-postal-code: $geoip_postal_code
config:
  use-geoip2: true

Local Usage

Build the Application

To build the application locally, use the following command:

go build

Run the Application

After building, execute the application as follows:

./headers

Send a Request

You can send a request to the locally running application using curl:

curl localhost:8082

Docker Usage

Build a Docker Image

To run the application within a Docker container, first build a Docker image:

docker build -t go-headers:1.0 .

Run the Docker Container

After building the Docker image, create and run a container:

docker run --name go-headers go-headers:1.0

Send a Request to the Dockerized Application

You can send a request to the application running inside the Docker container using curl:

curl localhost:8082

Example Output

The application will log the incoming request headers in JSON format to the console. Here's an example of the output:

{
  "Host": "localhost:8082",
  "User-Agent": "curl/7.68.0",
  "Accept": "*/*"
}

Feel free to use this tool to inspect HTTP request headers for debugging or analysis purposes.

License

This project is licensed under the MIT License.

About

simple golang app to print request headers to stdout json logs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published