Go Lang

How to Get Real Client IPs in Fiber When Using a Reverse Proxy

Build robust and modern HTTP servers in Go with practical code examples and best practices.

Getting Real Client IPs in Fiber Behind a Proxy

When your Fiber application runs behind a reverse proxy like Caddy, Nginx, or Cloudflare, you’ll notice that c.IP() returns the proxy’s IP address instead of your actual visitor’s IP. This happens because Fiber sees the direct connection, which is from the proxy server, not the original client.

Why This Happens

By default, Fiber reads the IP from the direct TCP connection for security reasons. Without proper configuration, it doesn’t know there’s a trusted proxy in front of it passing along the real client information in HTTP headers.

Level Up Your Go Web Server: Mastering Advanced Routing with net/http

Build robust and modern HTTP servers in Go with practical code examples and best practices.

Level Up Your Go Web Server: Mastering Advanced Routing with net/http

Building robust and maintainable web applications in Go often hinges on how effectively you manage incoming HTTP requests. While Go’s built-in net/http package provides foundational tools, its advanced routing features empower you to create sophisticated and organized application logic. This article will guide you through practical code examples for path parameters, HTTP method constraints, host-based routing, middleware, sub-routing, and context-elevating your Go web server development.

How to scrape page source with Go and chromedp

How to scrape page source with Go and chromedp

It’s clear what we are trying to achieve, so let’s consider the requirements. Firstly, we need a tool to render web pages since JavaScript is commonly used nowadays. Secondly, we require an API to communicate with the headless browser. Lastly, saving the result can be challenging as browsers are designed to interact with rendered results rather than directly with the source code.

Headless browser

So we are looking for a headless browser. We are going to use Chrome’s headless-shell because it’s easy to use, and it’s based on Chromium . The most significant advantage is docker image, which we can efficiently run on our local machine or anywhere in the cloud.

Golang and DynamoDB

Golang and DynamoDB

How to put data into dynamodb

I have been avoiding Amazon DynamoDB for a long time. Each time I tried to use it, either with PHP or GoLang always gave up very quickly. A while ago, I built up a solution storing a lot of JSON files on S3 buckets, and the costs of this solution (number of GET requests) started to escalate very quickly. I decided to try to migrate data to DynamoDB, and this time I was successful. I will try to explain how I did it and what I learned along the way.