By Roger Henman
I’m new to DO functions (using Go) and am really struggling with this. I’m trying to deploy a single function right now but I plan to add others - all of which will need to share some local libraries. I’m been trying to find a project structure or yml configuration that enables this but after almost two days I’m still stuck. I can build and run locally but when I try to deploy using doctl I get such as package common/models is not in GOROOT (/usr/local/go/src/common/models). My project structure is below. I have a shared package called “lib” that is shared among the functions, as well as other packages from the “common” module, all of which exist in a single workspace.
What do I need to do so that doctl knows where to find these packages when building?
repo
api
common
functions
functions
packages
bots
bot1
main.go
scrape.go
lib
objects.go
utilities.go
go.mod
go.sum
go.work
go.work.sum
Errors:
scrape.go:14:2: package api/common is not in GOROOT (/usr/local/go/src/api/common)
scrape.go:15:2: package api/handlers is not in GOROOT (/usr/local/go/src/api/handlers)
scrape.go:16:2: package api/logger is not in GOROOT (/usr/local/go/src/api/logger)
scrape.go:17:2: package common/models is not in GOROOT (/usr/local/go/src/common/models)
scrape.go:7:2: package functions/lib is not in GOROOT (/usr/local/go/src/functions/lib)
scrape.go:19:2: no required module provides package github.com/PuerkitoBio/goquery; to add it:
go get github.com/PuerkitoBio/goquery
scrape.go:20:2: no required module provides package github.com/labstack/gommon/log; to add it:
go get github.com/labstack/gommon/log
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!
Hi there,
If I remember correctly, for Go functions the build is always remote, and I think the issue comes from how the Go toolchain inside that environment resolves modules. The lib folder does get included by the Functions builder, but Go itself still expects anything you import to have a proper module path. When it sees something like functions/lib, it assumes you’re trying to import something from GOROOT, which explains the error you saw.
I haven’t tested this exact setup with Go in Functions, but giving the lib folder its own go.mod and importing it using a real module path is usually the safest approach. Something like turning lib into module github.com/you/project/lib and then importing that from your function. I believe the remote build should handle that correctly.
If none of these work, it’s definitely worth opening a support ticket with a minimal example. The Functions team can confirm how the Go runtime handles module resolution in your specific layout.
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.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.