Tag: Golang

Remove source path from Go’s panic stack trace

I would like to share the Golang’s build flag to remove the source path (GOPATH) from panic stack trace output. In production environments or commercial projects it is sometimes not ideal to display the source path because of privacy, security or other reasons. Below is an example of a stack trace output that reveals the […]

Continue Reading…

Controller Request Mapping in Golang

Background I’ve been developing web applications using Java and Spring Framework and in 2019, I started using Golang in some of my projects. So far my experience with Golang is great but I miss the annotation that Spring framework provides particularly the @RequestMapping for URL mapping, @Bean and @Autowired for dependency injection. Most of the […]

Continue Reading…

Two-letter country codes

Happy New Year! I hope you’re having a great time. Today, I am updating my online tool, ip.johnpili.com to use Cloudflare’s Request Header, “CF-IPCountry” so that I can display the IP address together with the country. I also want to have my own two-letter country code on my website as quick reference. The table below […]

Continue Reading…

Generate a self-signed certificate for Golang

Use OpenSSL generate a self-signed certificate for Golang. In this code snippetI created a certificate with validity of 15 years. openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 5475 Once you create the certificate and key you can use it in your Golang HTTP like this log.Fatal(http.ListenAndServeTLS(“:”+port, configuration.HTTP.ServerCert, […]

Continue Reading…

Randomly create a time.Sleep in Golang

To randomly create a time.Sleep in Golang you can use the code snippet below. You may want to simulate a load in your web server and have an arbitrary seconds or minutes before getting the reply. rand.Seed(time.Now().UnixNano()) delta := rand.Intn(60 + 1) // randomly generates numbers 1 to 60 time.Sleep(time.Duration(delta) * time.Second) // sleep and […]

Continue Reading…

Using reCAPTCHA with Golang

Overview Google’s reCAPTCHA is one of the tool we can use to stop malicious internet bots from abusing our web applications.It comes in two versions, reCAPTCHA v2 and v3. Version 3 uses a score based and no-interaction approach to handle bots from humans. Version 2 uses use a checkbox that will require users to answer […]

Continue Reading…

Develop a whatismyipaddress.com clone website using Golang

Do you want to build a website clone similar to whatismyipaddress.com? It is actually easy to develop. I decided to create this tool because I was working on an automated DNS client that will check my public IP address. Perhaps, somebody might need this in the future. I already made the completed demo available online […]

Continue Reading…