Skip to content

Commit

Permalink
created generate model file
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh4517 committed Sep 20, 2024
1 parent 0c932ad commit 33c859b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Empty file removed models/<model>.go
Empty file.
18 changes: 18 additions & 0 deletions models/generateModel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package models
import (
"fmt"
"os"
)
func generateModelFile(modelName string, fields []string) {
modelFile := fmt.Sprintf("./models/%s.go", modelName)
file, _ := os.Create(modelFile)
defer file.Close()

file.WriteString(fmt.Sprintf("package models\n\nimport \"gorm.io/gorm\"\n\ntype %s struct {\n", modelName))
for _, field := range fields {
file.WriteString("\t" + field + "\n")
}
file.WriteString("\tgorm.Model\n}\n")

fmt.Printf("Model for %s created successfully!\n", modelName)
}

0 comments on commit 33c859b

Please sign in to comment.