Using Swagger To Document Your Go Application

Adam Presley
2 min readNov 23, 2020
Photo by Bernd Klutsch on Unsplash

Go, commonly referred to as “Golang”, is a great language for writing RESTful service applications. Every good service application should have documentation describing its endpoints for future consumers, even if that consumer is you. Enter Swagger, one the best ways to document RESTful APIs. In this article I’ll talk about using a tool called swag to document and generate an endpoint for viewing your documentation.

Let’s start with a small, simple example application that exposes an endpoint that returns an array of values. In this example I’ll be using a framework called Echo, though you can just use the vanilla Go HTTP router if you so choose.

Next let’s make some documentation. To get started you will need to install swag. This is a command line tool used to generate documentation from annotations in your Go source code.

Now let’s modify our example by adding annotations in comments that will be the source for generating documentation.

--

--

Adam Presley

Just a guy who loves his wife, kids, and writing software.