ol := &ObjectList{ Items: []*ObjectItem{ &ObjectItem{ Keys: []string{"name"}, Val: &StringLiteral{ Value: "Alice", }, }, &ObjectItem{ Keys: []string{"name"}, Val: &StringLiteral{ Value: "Bob", }, }, }, }
nameVal, ok := ol.GetAttributeValue("name") if ok { fmt.Println(nameVal.(*StringLiteral).Value) }This code first checks if the "name" property exists in the ObjectList, and if so, uses a type assertion to convert the value to a StringLiteral and print its value. Overall, these examples demonstrate how the hashicorp/hcl AST package can be used to programmatically manipulate HCL objects and their properties. This package falls under the HashiCorp package library.