Question

How to use go packages with DO Functions?

How can external libraries from Go can be used in the FAAS product? I.e. running the following function:

package main

import "github.com/sirupsen/logrus"

func Main(args map[string]interface{}) map[string]interface{} {
	name, ok := args["name"].(string)
	if !ok {
		name = "stranger"
	}
	msg := make(map[string]interface{})
	msg["body"] = "Hello " + name + "!"
	logrus.Fatal("FAAS can't be used with external Go libraries like github.com/sirupsen/logrus i.e.")
	return msg
}

leads to the following error:

stderr: exec__.go:3:8: no required module provides package github.com/sirupsen/logrus; to add it:
stderr:  go get github.com/sirupsen/logrus
stderr: failed go build -o /tmp/action/1/bin/exec -ldflags -s -w 
stderr: in /tmp/action/1/src 
stderr: env {'GOROOT': '/usr/local/go', 'GOPATH': '/tmp/go', 'GO111MODULE': 'on', 'GOCACHE': '/tmp', 'PATH': '/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'}
stderr: 
stderr: The action did not initialize or run as expected. Log data might be missing.

After adding a go.mod / go.sum, the same error occured.

Help is really appreciated! Thanks in advance.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

I believe that you need to add the --remote-build flag to your doctl serverless deploy command in order for this to work.

Here is a link to a demo project that utilizes Go modules:

https://github.com/digitalocean/sample-functions-golang-presigned-url

The complete command from the example is:

doctl serverless deploy sample-functions-golang-presigned-url --remote-build

Best,

Bobby

This comment has been deleted