Skip to content
deploying Google Cloud Functions written in Golang with ease
Go JavaScript Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
api
examples
shim
.gitignore
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
deploy.go refactor(deploy): gcloud deployment moved to it's own file Jul 14, 2017
main.go
readme.md

readme.md

CloudFunc

GoDoc

CloudFunc is a command line tool (cli) that deploys Google Cloud Functions with ease. It uses node.js shim to wrap the Go binary as the Cloud Functions only support Node at the moment.

Only us-central region is supported while Google Cloud Functions are in Beta

Installation

Tested on Golang 1.8

Please follow gcloud sdk installation notes in case you don't have the gcloud command.

You will also need to update and install beta features at the moment

gcloud components update &&
gcloud components install beta

Finally download the cloudfunc with its SDK

go get -u github.com/flowup/cloudfunc/...

Code Example

This code example shows a simple cloud function that sends back whatever JSON it receives.

package main

import (
	"github.com/flowup/cloudfunc/api"
)

func main() {
	var input map[string]interface{} = make(map[string]interface{})
	
	cloudFunction := api.NewCloudFunc()
	req, err := cloudFunction.GetRequest()
	if err != nil {
		panic(err)
	}
	
	err = req.BindBody(&input)
	if err != nil {
		panic(err)
	}

	cloudFunction.SendResponse(&input)
}

Usage

Single deploy command is exposed by the cloudfunc. This allows to target a folder with main package that will be deployed to cloud functions. Name of the function will be derived from the name of the folder.

You need to also target the storage bucket that will be used to store contents of your function

cloudfunc deploy myfunction --bucket mybucket

Where:

  • myfunction is the folder with your function
  • mybucket is the name of your gcloud bucket

Configuration

Additional configurations can be done using function.json file within your function main package (look at the /examples folder).

{
  "name": "myfunctionname",
  "bucket": "mybucketname",
  "memory": 128,
  "timeout": 3
}

In case your bucket is specified within the function.json file, you can simply deploy with:

cloudfunc deploy example # where example is your function folder

SDK

There are two IO functions provided by github.com/flowup/cloudfunc/api:

// GetInput accepts an interface and unmarshalls the function input using json.Unmarshal
func GetInput(i interface{}) error {}
// Send marshalls given interface using json.Marshal and sends it back as a function output
// If the interface can't be serialized, it will be returned as a pure string
func Send(i interface{}) error
You can’t perform that action at this time.