我正在尝试重新部署一个在 Go 1.11 中在 Google Cloud Functions 中工作的 golang 函数,但现在我必须在 Go 1.13 中部署,我收到以下错误:
构建失败:函数的 go.mod 中的模块路径必须包含 第一个路径元素中斜杠之前的点,例如example.com/module, 发现:iotpubsub;错误 ID:90dcdd2e
函数.go:
package iotpubsub
import (
"context"
"errors"
"fmt"
"log"
iot "cloud.google.com/go/iot/apiv1"
iotpb "google.golang.org/genproto/googleapis/cloud/iot/v1"
)
// Configuration options
// You must update these values to match your environment!
const (
region = "us-central1"
projectID = "myprojectID"
registryID = "myRegistryID"
)
var client *iot.DeviceManagerClient
func init() {
var err error
client, err = iot.NewDeviceManagerClient(context.Background())
if err != nil {
log.Fatalf("iot.NewDeviceManagerClient: %s", err)
}
}
// PubSubMessage implements the Pub/Sub model.
type PubSubMessage struct {
Data []byte `json:"data"`
Attributes map[string]string `json:"attributes"`
}
// Send sends the Pub/Sub message to the device.
func Send(ctx context.Context, m PubSubMessage) error {
deviceID, ok := m.Attributes["deviceId"]
if !ok {
return errors.New("deviceId is missing in Attributes")
}
subFolder, ok := m.Attributes["subFolder"]
if !ok {
return errors.New("subFolder is missing in Attributes")
}
deviceName := fmt.Sprintf("projects/%s/locations/%s/registries/%s/devices/%s", projectID, region, registryID, deviceID)
_, err := client.SendCommandToDevice(ctx, &iotpb.SendCommandToDeviceRequest{
Name: deviceName,
BinaryData: m.Data,
Subfolder: subFolder,
})
if err != nil {
return fmt.Errorf("SendCommandToDevice: %s", err)
}
return nil
}
go.mod:
module iotpubsub
go 1.13
require (
cloud.google.com/go v0.39.0
google.golang.org/genproto v0.0.0-20190605220351-eb0b1bdb6ae6
)
我应该怎么做才能修复该错误? 预先感谢。
尝试调用您的模块
iotpubsub.com
或任何其他看起来像正确域的东西。官方文档在这里:https://golang.org/ref/mod#go-mod-file-ident
另请查看 https://blog.golang.org/migration-to-go-modules 以及该系列中的其他帖子。
有什么解决办法吗?我也面临着同样的问题。