{
"path": "/posts/2016/2016-04-22-first-go-module",
"site": "at://did:plc:mracrip6qu3vw46nbewg44sm/site.standard.publication/self",
"tags": [
"code",
"go"
],
"$type": "site.standard.document",
"title": "Creating a Go module",
"updatedAt": "2016-04-22T09:40:00.000Z",
"publishedAt": "2016-04-22T09:40:00.000Z",
"textContent": "Creating a Go module\n\nWe're going to create a CLI tool for sending a message to a channel in Slack using the command line. This post is similar to my earlier post: Creating an Elixir Module. We'll be using the chat.postMessage Slack API endpoint. Also, make sure you have a Slack API token.\n\nOur CLI syntax will be:\n\nFirst, make sure you have your $GOPATH set properly.\n\nNext, set your Slack token as an environment variable:\n\nTypically, developers will use one folder for all of their Go code, and create new folders within for each new project. My structure looks like this:\n\nMake a folder called slack within src, then inside that folder create the following files and folders as well:\n\nUsing the builtin Go command line parser flag, we will write our main.go file to parse the message and channel from the command line.\n\nslack/main.go\n\nThis sets us up with a CLI parser which will take our provided arguments and pass them to the SendMsg function, which we will define now.\n\nMake sure you have set the environment variable SLACK_TOKEN with your token.\n\nslack/api/slack.go\n\nWith these two files written, we can go the to slack folder and test the program:\n\nIf all goes well, you will see the output:\n\nand the message will show up from you to slackbot in the Slack app.\n\nTo build the program as a standalone, distributable binary run:\n\nThis creates a binary file called slack in the folder, which can be run with:\n\nThat's it!\n\nThanks to Hans Li for the help with testing!",
"canonicalUrl": "https://www.danielcorin.com/posts/2016/2016-04-22-first-go-module"
}