简体   繁体   中英

Deploying Go subpackages to Google Cloud Functions fails

I'm trying to deploy a function to GCF but it's failing no matter what I try. This is the error returned every time:

Build failed: 2021/03/02 18:02:46 Unable to extract package name: unable to find Go package in /workspace/serverless_function_source_code.
exit status 1; Error ID: aba1aa6a

I've read a few answers here and I tried to fix the issue as told, but I keep having this error and I'm lost at this point.

My project structure is as follow:

.
|--function.go
|--go.mod
|--go.sum
|--subpackage
`        |--subpackage.go

My main function uses some stuff from subpackage.go and the function.go import is:

package function

import (
    "fmt"
    "log"
    "net/http"

    // remote imports //
    
    modname/subpackage
)

and then the go.mod file:

module modname

go 1.13

require (
    // remote imports //

    modname/subpackage
)

The subpackage is initialized as package subpackage and I think this is what the GCF docs say.

In function.go I have a function called Start that I indicated as the entrypoint in the setup. I'm lost and I have no idea how to work around this.

Ok, found the problem. If you have my issue, ignore the go.mod file in my question, as it was rigthly suggested on an other answer that you should not include the local packages.

But my problem wasn't that. I was zipping and uploading the FOLDER containing the project, not the file inside the folder. GCF than unzipped the.zip and found an other folder with the project inside.

Your go.mod and function.go files have to be at the first level. Hope this will save time for someone else.

Delete the reference of your subpackage in your go.mod file. When the subpackage is bellow the function.go file you don't need to reference it in the go.mod file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM