Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Consume RESTful API Endpoints Within A Golang Application

I am a huge fan of the Go programming language and have written a decent amount of material on the subject. For example, a popular tutorial I wrote titled, Create a Simple RESTful API with Golang, focuses on developing an API. However, I recently received questions on the subject of consuming data from other APIs from within a Go application.

We’re going to see how to issue HTTP requests from within Go, in an effort to consume or send data to other RESTful APIs that might exist on the internet.

Read More

Add Two-Factor Authentication To A Golang RESTful API

When it comes to authenticating users for making use of your API, it is a good idea to add an extra step beyond standard username and password. This is called two-factor authentication (2FA) and it acts as a second layer of security for users making use of your application.

Not too long ago I had written about adding 2FA to a RESTful API created with Node.js and Express Framework, but what if we wanted to do it in Golang? The logic isn’t any different, just a new syntax for a new language.

We’re going to see how to add two-factor authentication to a Golang API that makes use of Json Web Tokens (JWT).

Read More

Using Network Sockets With The Go Programming Language

A few months back I wrote about using websockets in a Golang application for communication with an Angular client web application. While very useful and simplistic, in many cases websockets won’t be the means for real-time communication between applications. It is often easier or better to use standard TCP network sockets as an alternative. For example, if you’re developing an online video game, it will likely communicate to the server using TCP sockets rather than websockets.

We’re going to see how to create a basic chat application using the Go programming language. This chat application will have a server for listening and routing client communications and a client for sending and receiving messages from the server.

Read More

Concurrent Golang Applications With Goroutines And Channels

One of the highlights of the Go programming language is its ability to handle concurrency with minimal effort using what are called goroutines and channels. The beauty here versus other programming languages is that you don’t end up in a callback mess or locking hell. In fact, you can even create far more goroutines in Go than you can in a language such as Java with the same hardware.

We’re going to see an example where we have an application that starts several worker goroutines and shares a channel for accessing data.

Read More

Cross Compiling Golang Applications For Use On A Raspberry Pi

I recently invested in yet another Raspberry Pi, this time the new Raspberry Pi Zero W, which has wireless and bluetooth. I also made a leap and bought the camera module with it because the new official case by Raspberry Pi has a camera attachment. Probably the most popular development technology for Raspberry Pi is Python, but I am not a fan at all. Instead, I’ve been doing a lot of Go development and figured that would be my best bet when it comes to developing a camera application for the Raspberry Pi. The problem with this is that if I were to compile a Go application on the Raspberry Pi Zero itself, it would probably take ten years (I joke).

Cross compiling is a thing and we’re going to see how to do this via a different operating system and architecture, yet have it be compatible on the Raspberry Pi.

Read More

Using A SQLite Database For Local Data In A Golang Application

When developing an application with the Go programming language, you might find yourself needing to save data locally. If you’ve been keeping up you’ll remember that I’ve written about storing data remotely with Golang in a Couchbase NoSQL database, but never anything locally. Probably the easiest way to store data locally is with a SQLite database as it is a solid technology that has been around for a while.

We’re going to see how to use a SQLite database in our Golang application to read and write local data.

Read More

Decode Map Values Into Native Golang Structures

I personally think that Golang is a great development technology and one of the better that I’ve used. However, there is no such thing as a perfect development technology. That said, there are things to be desired in Golang out of the box. For example, I always find myself wishing that I could use type assertions to decode map values into a defined Go data structure.

Using a nifty package, this actually becomes a possibility and without much extra effort. We’re going to see how to take a map and convert it into a custom structure.

Read More