Netlify's documentation on deploying multiple Golang functions has a few pain points. First, deploying multiple functions on their system without the constant need to update the Makefile as this example would have required. Second, deploying without a frontend introduces some small changes. This example attempts to streamline Netlify's already easy-to-use deployment system even further.
Golang refers to the Go Programming Language. They may be used interchangeably below.
What made this all work together were the following:
- Makefile - A file instructing the make command how to build the software. In this case, we're just telling it what the go-tool should do to the packages (hello and goodbye folders).
- "make build" command is called upon by Netlify's deployment system and uses the Makefile.
- GO_IMPORT_PATH tells the go-tool where to fetch the golang source code. What we're doing is using the Netlify system to just run our go-tool to create the functions and deploy it to the cloud for us.
- When you see something like "./..." that tells the go-tool to go through the current directory (or GOPATH) and find all the packages to look at.
The following assumes you have some git basics. It also assumes you have a Netlify account authorized to access your GitHub repos.
-
Change this to point to your fork instead of mine.
-
Go to app.netlify.com to login.
-
Click on "New site from Git".
-
Select "GitHub". Requires configuring Netlify with GitHub.
-
Select or Find "GolangNetlifyFunctions" from the list.
-
Ensure the "Branch to deploy" drop-down field is set to master.
-
Click on "Deploy site".
-
Click on "Deploys" tab at the top of the page.
-
Wait for the first entry to change its status to: PUBLISHED.
-
Click on "Functions" tab at the top of the page.
-
You should see one function for "hello" and another for "goodbye".
-
If you click on either one, and visit the Endpoint under the function name of the form:
https://[something-clever-netlify-made-for-you].netlify.com/.netlify/functions/[function-name]
...you will see either the words, "Hello, World!" or "Goodbye, World!"
-
Congratulations, you've just deployed a pure backend filled with Golang Netlify functions!
Simply create a directory on the first level of this repo, next to the "hello" and "goodbye" directories, and fill it with go files! This setup takes care of the rest!!! Have fun!
-
A reference to the hack here that made this all work. Project assumes Netlify's build repo root will always be: /opt/build/repo
-
Where your Netlify functions end up living is defined in this functions line.
-
If you desire, change the name of your functions folder in the netlify.toml. We'll call this new name, FUNCS_FOLDER_NAME.
If you make this change, be sure to change the GOBIN entry in the netlify.toml file, appropriately.
For instance, if your FUNCS_FOLDER_NAME = llama, you should change this line to:
GOBIN=/opt/build/repo/llama