Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make auto-gen code to leave generated code seperated with endpoint.go #259

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions hack/endpoint-codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ type endpointDecl struct {
Group string
}

//const indexTemplateStr = ` // This is generated code. DO NOT EDIT.
//
//package api
//
//type Endpoint int
//type EndpointInfo struct {
// Name string
// Group string
//}
//`
const indexTemplateStr = ` // This is generated code. DO NOT EDIT.

package api

`

//const endpointTemplateStr = `// Comment below is special purpose for code generation.
//// Do not edit this comment.
Expand Down Expand Up @@ -129,16 +124,16 @@ func main() {
log.Printf("Endpoint: %s, Group: %s\n", ep.Name, ep.Group)
}

//// contents for index
//indexTemplate := template.New("index")
//indexTemplate, err = indexTemplate.Parse(indexTemplateStr)
//if err != nil {
// log.Fatalf("failed to parse template: %v", err)
//}
//var indexCode bytes.Buffer
//if err := indexTemplate.Execute(&indexCode, endpoints); err != nil {
// log.Fatalf("failed to execute template: %v", err)
//}
// contents for index
indexTemplate := template.New("index")
indexTemplate, err = indexTemplate.Parse(indexTemplateStr)
if err != nil {
log.Fatalf("failed to parse template: %v", err)
}
var indexCode bytes.Buffer
if err := indexTemplate.Execute(&indexCode, endpoints); err != nil {
log.Fatalf("failed to execute template: %v", err)
}

//// contents for endpoint
//endpointTemplate := template.New("endpoint")
Expand Down Expand Up @@ -186,7 +181,7 @@ func main() {

// replace original file(endpointFilePath) with new contents
//contents := indexCode.String() + endpointCode.String() + apiMapCode.String() + stringFunctionCode.String() + getEndpointFunctionCode.String()
contents := apiMapCode.String() + stringFunctionCode.String() + getEndpointFunctionCode.String()
contents := indexCode.String() + apiMapCode.String() + stringFunctionCode.String() + getEndpointFunctionCode.String()
newFilePath := strings.Replace(endpointFilePath, "endpoint", "generated_endpoints.go", 1)

if err := ioutil.WriteFile(newFilePath, []byte(contents), 0644); err != nil {
Expand Down
Loading
Loading