как я могу чувствовать поле в структуре RunInstancesInput - PullRequest
0 голосов
/ 12 июня 2019

Я хотел бы улучшить структуру RunInstancesInput значениями, которые я определил в файле json.

Я создал файл json, преобразовав вывод DescribeInstance в json.

Если японять ошибку, go не может найти определение типа: 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
...