简体   繁体   English

go 编译错误:结构文字中的未知字段

[英]go compile error: unknown field in struct literal

I have a go package that has the following struct:我有一个 go package 具有以下结构:

package transforms
type MqttConfig struct {
    Qos            byte  
}

type KeyCertPair struct { 
    KeyFile      string 
}    

In my main.go, I import the package and use both of them liek this:在我的 main.go 中,我导入了 package 并使用它们,如下所示:

    import ( sdkTransforms "github.com/edgexfoundry/app-functions-sdk-go/pkg/transforms")

    type AWSMQTTConfig struct {
        MQTTConfig  *sdkTransforms.MqttConfig
        KeyCertPair *sdkTransforms.KeyCertPair
    }

    config := AWSMQTTConfig{}

    //FIRST
    pair := &sdkTransforms.KeyCertPair{
            KeyFile:  mqttKey,
    }

    //SECOND
    mqttcfg := &sdkTransforms.MqttConfig{
            Qos:            2,    
    }

But only the second usage gives me this compile error:但只有第二种用法给了我这个编译错误:

unknown field 'Qos' in struct literal of type transforms.MqttConfig

I don't understand what's wrong.我不明白出了什么问题。

It is possible that you are pointing to a version of the sdkTransforms package that doesn't have that field for MqttConfig.您可能指向的 sdkTransforms package 版本没有 MqttConfig 的该字段。 You can do a go get <module> to get the latest version and try again.您可以执行go get <module>以获取最新版本并重试。

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

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