Create Cloud Functions for Go runtime

This section describes how to create Cloud Functions for the Go runtime.

Create SOULs Go runtime Cloud Functions

Create functions using the souls create functions command.

$ souls create functions method1
✓ Created file ./apps/cf-go116-method1/function.go
✓ Created file ./apps/cf-go116-method1/go.mod
✓ Created file ./apps/cf-go116-method1/.env.yaml

SOULs Go Runtime Cloud Functions directory structure

├── cf-go116-method1
│   ├── function.go
│   ├── mod.go
│   ├── .env.yaml

Define the main function.go in function.go.


// Package p contains an HTTP Cloud Function.
package p

import (

// HelloWorld prints the JSON encoded "message" field in the body
// of the request or "Hello, World!" if there isn't one.
func cf_go116_method3(w http.ResponseWriter, r *http.Request) {
  var d struct {
    Message string `json:"message"`

  if err := json.NewDecoder(r.Body).Decode(&d); err != nil {
    switch err {
    case io.EOF:
      fmt.Fprint(w, "Hello World!")
      log.Printf("json.NewDecoder: %v", err)
      http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)

  if d.Message == "" {
    fmt.Fprint(w, "Hello World!")
  fmt.Fprint(w, html.EscapeString(d.Message))

Run SOULs Functions locally

Install functions-framework .

$ go install

Note: First, create the cmd / main.go file as described on the Functions Framework for Go site.

cd cmd
go build

Now access the link below and try calling GET Functions.


Hello World!

If the response is returned, it is successful.

Deploy SOULs Go runtime Cloud Functions

Deploy using the SOULs functions command.

$ cd apps/cf-go116-method1 $ souls functions deploy

Check the URL of SOULs Functions

Check using the SOULs functions command.

$ souls functions url

Check the URLs of all SOULs Functions

Check using the SOULs functions command.

$ souls functions all_url