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.

Hi @ocmer

I ran into the same issue as you, I was able to get it to work by moving the go.mod and go.sum files into the same directory as the main.go file.

You can see my function here: https://github.com/jonasbn/pxy-redirect-ow-function

Found the answer here: https://www.digitalocean.com/community/questions/functions-go-build-error-no-required-module-provides-package

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

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    card icon
    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Sign up
    card icon
    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

    Learn more
    card icon
    Become a contributor

    You get paid; we donate to tech nonprofits.

    Learn more
    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

    Learn more ->
    DigitalOcean Cloud Control Panel
    Get started for free

    Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

    New accounts only. By submitting your email you agree to our Privacy Policy.