By Ocmer
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.
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!
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.
This comment has been deleted
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
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
