我如何感觉到RunInstancesInput结构中的字段

时间:2019-06-12 09:15:32

标签: aws-sdk-go

我想使用我在json文件中定义的值来增强结构RunInstancesInput。

我通过将DescribeInstance的输出转换为json来创建json文件。

如果我理解该错误,则无法找到类型定义:BlockDeviceMapping,CapacityReservationSpecification等,等等。 所以也许我应该导入正确的库? 这是我的代码:

package main

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/ec2"
    "encoding/json"
    "fmt"
    "io/ioutil"
)

func main() {

    // read file
    data, err := ioutil.ReadFile("./example.json")
    if err != nil {
      fmt.Print(err)
    }


    type RunInstancesInput struct {
        AdditionalInfo *string `locationName:"additionalInfo" type:"string"`
        BlockDeviceMappings []*BlockDeviceMapping `locationName:"BlockDeviceMapping" locationNameList:"BlockDeviceMapping" type:"list"`
        CapacityReservationSpecification *CapacityReservationSpecification `type:"structure"`
        ClientToken *string `locationName:"clientToken" type:"string"`
        CpuOptions *CpuOptionsRequest `type:"structure"`
        CreditSpecification *CreditSpecificationRequest `type:"structure"`
        DisableApiTermination *bool `locationName:"disableApiTermination" type:"boolean"`
        DryRun *bool `locationName:"dryRun" type:"boolean"`
        EbsOptimized *bool `locationName:"ebsOptimized" type:"boolean"`
        ElasticGpuSpecification []*ElasticGpuSpecification `locationNameList:"item" type:"list"`
        ElasticInferenceAccelerators []*ElasticInferenceAccelerator `locationName:"ElasticInferenceAccelerator" locationNameList:"item" type:"list"`
        HibernationOptions *HibernationOptionsRequest `type:"structure"`
        IamInstanceProfile *IamInstanceProfileSpecification `locationName:"iamInstanceProfile" type:"structure"`
        ImageId *string `type:"string"`
        InstanceInitiatedShutdownBehavior *string `locationName:"instanceInitiatedShutdownBehavior" type:"string" enum:"ShutdownBehavior"`
        InstanceMarketOptions *InstanceMarketOptionsRequest `type:"structure"`
        InstanceType *string `type:"string" enum:"InstanceType"`
        Ipv6AddressCount *int64 `type:"integer"`
        Ipv6Addresses []*InstanceIpv6Address `locationName:"Ipv6Address" locationNameList:"item" type:"list"`
        KernelId *string `type:"string"`
        KeyName *string `type:"string"`
        LaunchTemplate *LaunchTemplateSpecification `type:"structure"`
        LicenseSpecifications []*LicenseConfigurationRequest `locationName:"LicenseSpecification" locationNameList:"item" type:"list"`
        MaxCount *int64 `type:"integer" required:"true"`
        MinCount *int64 `type:"integer" required:"true"`
        Monitoring *RunInstancesMonitoringEnabled `type:"structure"`
        NetworkInterfaces []*InstanceNetworkInterfaceSpecification `locationName:"networkInterface" locationNameList:"item" type:"list"`
        Placement *Placement `type:"structure"`
        PrivateIpAddress *string `locationName:"privateIpAddress" type:"string"`
        RamdiskId *string `type:"string"`
        SecurityGroupIds []*string `locationName:"SecurityGroupId" locationNameList:"SecurityGroupId" type:"list"`
        SecurityGroups []*string `locationName:"SecurityGroup" locationNameList:"SecurityGroup" type:"list"`
        SubnetId *string `type:"string"`
        TagSpecifications []*TagSpecification `locationName:"TagSpecification" locationNameList:"item" type:"list"`
        UserData *string `type:"string"`
    }

    // json data
    var obj RunInstancesInput

    // unmarshall it
    err = json.Unmarshal(data, &obj)
    if err != nil {
        fmt.Println("error:", err)
    }

} 

当我尝试编译代码时,出现以下错误:

# command-line-arguments
./json.go:4:2: imported and not used: "github.com/aws/aws-sdk-go/aws"
./json.go:5:5: imported and not used: "github.com/aws/aws-sdk-go/aws/session"
./json.go:6:5: imported and not used: "github.com/aws/aws-sdk-go/service/ec2"
./json.go:23:29: undefined: BlockDeviceMapping
./json.go:24:40: undefined: CapacityReservationSpecification
./json.go:26:18: undefined: CpuOptionsRequest
./json.go:27:27: undefined: CreditSpecificationRequest
./json.go:31:33: undefined: ElasticGpuSpecification
./json.go:32:38: undefined: ElasticInferenceAccelerator
./json.go:33:26: undefined: HibernationOptionsRequest
./json.go:33:26: too many errors

0 个答案:

没有答案