繁体   English   中英

Golang Cloud Function 构建失败:函数的 go.mod 中的模块路径必须在斜杠之前的第一个路径元素中包含一个点

[英]Golang Cloud Function Build failed: the module path in the function's go.mod must contain a dot in the first path element before a slash

我正在尝试使用 Go 1.11 重新部署在 Google Cloud Functions 中工作的 golang function 但现在我必须在 Z5F075AE3E1F9D0382BB8C4632991F9F9 中部署以下错误:

构建失败:函数的 go.mod 中的模块路径必须在斜杠之前的第一个路径元素中包含一个点,例如 example.com/module,找到:iotpubsub; 错误 ID:90dcdd2e

Function.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/migrating-to-go-modules和该系列中的其他帖子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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