From 33c859b4620cd7398f33b316aa1aac625a3cd5f8 Mon Sep 17 00:00:00 2001 From: Utkarsh4517 Date: Fri, 20 Sep 2024 05:53:32 +0530 Subject: [PATCH] created generate model file --- models/.go | 0 models/generateModel.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) delete mode 100644 models/.go create mode 100644 models/generateModel.go diff --git a/models/.go b/models/.go deleted file mode 100644 index e69de29..0000000 diff --git a/models/generateModel.go b/models/generateModel.go new file mode 100644 index 0000000..3da90a3 --- /dev/null +++ b/models/generateModel.go @@ -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) +} \ No newline at end of file