Skip to content

Commit

Permalink
Merge pull request #3992 from hashicorp/recaser
Browse files Browse the repository at this point in the history
`tools/generator-go-sdk` - add init() in id generator
  • Loading branch information
catriona-m authored Apr 12, 2024
2 parents 64934f1 + f3a5245 commit dfcf935
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tools/generator-go-sdk/internal/generator/templater_id_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ import (
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids/recaser"
)
%[2]s
%[3]s
%[4]s
`, data.packageName, *copyrightLines, *structBody, *methods)
%[5]s
`, data.packageName, *copyrightLines, r.registerId(), *structBody, *methods)
return &out, nil
}

Expand Down Expand Up @@ -83,6 +85,15 @@ type %[1]s struct {
return &out, nil
}

func (r resourceIdTemplater) registerId() string {
wordifiedName := wordifyString(r.name)
return fmt.Sprintf(`
func init() {
recaser.RegisterResourceId(&%[2]s{})
}
`, wordifiedName, r.name)
}

func (r resourceIdTemplater) methods() (*string, error) {
nameWithoutSuffix := strings.TrimSuffix(r.name, "Id")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ import (
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids/recaser"
)
// acctests licence placeholder
func init() {
recaser.RegisterResourceId(&BasicTestId{})
}
var _ resourceids.ResourceId = &BasicTestId{}
// BasicTestId is a struct representing the Resource ID for a Basic Test
Expand Down Expand Up @@ -183,10 +188,15 @@ import (
"strings"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids/recaser"
)
// acctests licence placeholder
func init() {
recaser.RegisterResourceId(&ConstantOnlyId{})
}
var _ resourceids.ResourceId = &ConstantOnlyId{}
// ConstantOnlyId is a struct representing the Resource ID for a Constant Only
Expand Down

0 comments on commit dfcf935

Please sign in to comment.