Env Variables in Go Functions

Are environment variables exposed to functions written in Go? How? The docs seem unclear on this.

Yes. It’s the same as how you’d normally use ENVs with Go: os.Getenv("FOO").

Awesome! Thanks for the quick reply.

A couple followups if you don’t mind…

  • Can Go functions do the “On Demand Builder” thing, where the return result is cached?
  • Can Go functions be “Scheduled”? (I know it’s beta)

Unfortunately, no. Since On Demand Builders depend on builder function from @netlify/functions npm package, they’re for JavaScript/TypeScript only.

I think you can use netlify.toml file to specify the schedule. You won’t be able to specify the schedule within the function.

1 Like

You may be interested in my blog post on deploying Go apps to Netlify: How to Use Netlify to Deploy a Free Go Web Application · The Ethically-Trained Programmer Since then Netlify has released advanced env vars so you can specify if you want the variable to be available at build time or runtime.

Love the Shop Talk podcast, cheers.

1 Like