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

Load A JSON Configuration From File In A Golang Application

Have you ever built an application and decided that you didn’t want to hardcode a bunch of values that might change frequently? The answer is, probably yes. When building a web application, it is common to separate configuration details into a separate file which might contain database information, hostnames, passwords, and anything else that probably shouldn’t exist in the application as hard-coded values.

We’re going to see how to open a JSON configuration file using the Go programming language and load it into a custom data structure to be used throughout the application.

Read More

Authenticate A Golang API With JSON Web Tokens

Over the past few weeks I’ve been doing a lot of investigation into JSON Web Tokens (JWT) for authentication in APIs. If you’ve been keeping up, you’ll remember I wrote about JWT authentication in a Node.js application as well as building a client facing NativeScript and Angular mobile application that made use of the Node.js backend. This is great, but what if you’re not very fond of JavaScript development?

We’re going to see how to create a backend API that creates and validates JSON Web Tokens using the Go programming language. This teach us how to create an API that offers an authentication mechanism outside of sessions and cookies, which typically are not available when working with an API.

Read More

TPDP Episode #13: The Go Programming Language And Modern Development

I am pleased to announce that the latest episode of The Polyglot Developer Podcast has been published to all the popular podcasting networks which include, but are not limited to, iTunes and Pocket Casts. In this episode titled, The Go Programming Language and Where it Fits in Modern Development, I am joined by Go advocate, Matt Holt, where we discuss Go as an option to modern development.

In this episode we discuss where Go excels and how it compares to other popular development technologies such as PHP and Node.js.

Read More

Parse CSV Data Using The Go Programming Language

Ever found yourself working with comma separated value (CSV) data from a file or other source? This format is easy to generate if you’re working with spreadsheet applications like Google Sheets or Microsoft Excel, and RDBMS applications. So how do we load this data and work with it in an application? More specifically an application built with the Go programming language?

We’re going to see how to take a CSV file and load it into a custom data structure to eventually be printed as JSON within the application.

Read More

Bundle HTML, CSS, And JavaScript To Be Served In A Golang Application

So I’ve been working on a project that uses the Go programming language. The application I’m building is a web application that I plan to distribute. The thing is, I don’t want to distribute hundreds of files to make it possible. The application has an API built with Go and the front-end that consumes the API is built with Angular. This lead me searching for a way to bundle all the files into the final binary.

There are several packages that exist for bundling assets into a Golang application. Popular packages include go-bindata, go-bindata-assetfs, and go.rice. I had the most success with go.rice, so we’re going to explore it in this article.

Read More

Parse XML Data In A Golang Application

While I don’t see a lot of it anymore, XML is still a common data format that people use. I prefer JSON, but I don’t always have a say in how I receive data. Some time ago I wrote a few tutorials on which include parsing XML data with Node.js, parsing XML data with Java, and parsing XML data with PHP. If you’ve been keeping up, I’ve been doing a lot of development with the Go programming language which is why I think it would be a great idea to go over XML in Golang.

Of the various programming languages, I think XML is the easiest to work with in the Go programming language. We’re going to see how to take XML data and unmarshal it into a custom structure. We’re also going to see how to take JSON data and convert it into XML.

Read More

Unit Testing A Golang Application That Includes HTTP

When building a great application, it is a good idea to plan for proper testing of each of the components that make the application tick. Through unit testing, we can test each function within the application as a separate entity, to make sure it performs based on our testing criteria.

But how do you do this in a Golang application? What if you need to test endpoints that were created using the Gorilla mux package?

We’re going to see how to develop unit tests for our functions as well as HTTP endpoints in a Golang application using the available Go testing framework.

Read More