Skip to content

How to deploy multiple golang Netlify functions without a frontend.

Notifications You must be signed in to change notification settings

phoenixcoder/GolangNetlifyFunctions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GolangNetlifyFunctions

Purpose

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.

Important Pieces

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.

How to deploy this example...

The following assumes you have some git basics. It also assumes you have a Netlify account authorized to access your GitHub repos.

  1. Fork this repo.

  2. Change this to point to your fork instead of mine.

  3. Go to app.netlify.com to login.

  4. Click on "New site from Git".

  5. Select "GitHub". Requires configuring Netlify with GitHub.

  6. Select or Find "GolangNetlifyFunctions" from the list.

  7. Ensure the "Branch to deploy" drop-down field is set to master.

  8. Click on "Deploy site".

  9. Click on "Deploys" tab at the top of the page.

  10. Wait for the first entry to change its status to: PUBLISHED.

  11. Click on "Functions" tab at the top of the page.

  12. You should see one function for "hello" and another for "goodbye".

  13. 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!"

  14. Congratulations, you've just deployed a pure backend filled with Golang Netlify functions!

How do I add more functions to this...

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!

References

Appendix

Other Info

  • 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
    

About

How to deploy multiple golang Netlify functions without a frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published