IBM Cloud Functions Adds Native Support for Go 1.11

5 min read

By: Carlos Santana

What’s happening with IBM Cloud Functions and Go?

I’m excited to announce that IBM Cloud Functions officially supports Go natively. Previously, we explained how to use Docker Actions in order to work with Go, but this was not native to Go developers. Now, Go developers can write a function and process the input and the output with normal function parameters and return values.

Ready to try it out?

You can deploy an example action by using the IBM Cloud CLI. Console UI support for Go is coming soon.

Here is a simple hello world action:

// Main says Hello
func Main(params map[string]interface{}) map[string]interface{} {
  name, ok := params["name"].(string)
  if !ok {
    name = "World"
  }
  res := make(map[string]interface{})
  res["body"] = "Hello " + name + "!"
  return res
}

Create a web action with the IBM Cloud Functions CLI plugin. Note: As a best practice, always specify the kind when you use the CLI to be sure that you are working with the version of the language that you expect:

ibmcloud fn action update helloGo hello.go --kind go:1.11 --web true

Next, get the URL for the web action and open it in your browser:

ibmcloud fn action get helloGo --url

Compile for production

To avoid latency with cold starts, it’s recommended that you compile and deploy your Go Action executable. By doing so, the action doesn’t have to compile the code in the first invocation. Another benefit is that compiling your code allows you to use multiple source files and vendor dependency libraries.

Further learning

To see how easy it is to set a project and compile and deploy your Go Action, check out the documentation.

Be the first to hear about news, product updates, and innovation from IBM Cloud