Functions - Go build error (no required module provides package)

Hey everyone!

So I am playing around with serverless functions and Go but as soon as I add a module from Github the script fails. Here is a minimal example:

package main

import (


type Request struct {
  Token   string `json:"token"`

type Response struct {
  StatusCode int    `json:"statusCode,omitempty"`
  Body       string `json:"body,ommitempty"`

func Main(in Request) (*Response, error) {

  client := godo.NewFromToke(in.Token)

  return &Response{
    StatusCode: http.StatusOK,
    Body:       "Yay!",
  }, nil

The error when executing doctl serverless deploy <folder> is

Deploying '/user/sample/test'
  to namespace '...'
  on host '...'
Submitted action 'test' for remote building and deployment in runtime go:default (id: ...)
Transcript of remote build session for 'test':
Output of failed build in /tmp/slices/builds/.../sample_test/2022-07-23T22-30-16.224Z/packages/sample/test
initializing modules
go: creating new go.mod: module exec
go: to add module requirements and sums:
        go mod tidy
test.go:6:2: no required module provides package; to add it:
        go get

Error: While deploying action 'sample/test': './' exited with code 1

Does anyone have an idea what I am doing wrong? Thanks a lot for the help I really appreciate it :)

Submit an answer
Answer a question...

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.

You have to put your go.mod and go.sum files directly in the package where you have the function’s code, in your case /tmp/slices/builds/.../sample_test/2022-07-23T22-30-16.224Z/packages/sample/test

Did you: go get as the error shows?

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.