Member-only story
Golang SlackBot Tutorial
Manage Static Assets in Golang
New ways to do it with Golang 1.16 new package “embed” — Ideal for SlackBots

Golang 1.16 new embed package helps you manage static assets, embedding them in the application binary and making them easy to use. I can see several applications of this new package, including managing JSON payload for my Slack Bot messages.
Overview of the new package embed
Any files from a package or package subdirectory can be embedded and retrieved as a variable of type string or bytes[].
You can also retrieve your embedded files with a variable of type FS and, you can even define which file needs to be embedded in your application using a glob pathname.
Use case: Using embed in a SlackBot
Given how easy it is to create and edit your messages using Block-kit Builder, I believe that the most convenient method to design and maintain your SlackBot is to save the design created with Block-kit JSON payload. The new embed package is the perfect feature for This case.
In terms of design pattern, those JSON payloads represent the View in a classical MVC application. Besides, we can send those messages as is or use some templating to include any data.
In my Slack demo application, I have used this method in all my Views combined with Go markup language. In this section, I will be demonstrating how to manage a greeting message designed with Block-kit. I will only focus on the View part of the application, ignoring the Model and Controller along. Nevertheless, feel free to peak at them in my git…