簡體   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