11package internal
22
33import (
4+ _ "embed"
45 "errors"
56 "log"
67 "os"
@@ -11,13 +12,17 @@ import (
1112)
1213
1314const (
14- gitignoreTmplPath = "templates/.gitignore.tmpl"
15- mainTmplPath = "templates/main.cpp.tmpl"
16- srcPath = "src"
17- binPath = "bin"
18- includePath = "include"
15+ srcPath = "src"
16+ binPath = "bin"
17+ includePath = "include"
1918)
2019
20+ //go:embed templates/.gitignore.tmpl
21+ var gitignoreTmpl string
22+
23+ //go:embed templates/main.cpp.tmpl
24+ var mainTmpl string
25+
2126type Project struct {
2227 ProjectName string
2328 AbsolutePath string
@@ -67,14 +72,14 @@ func (p *Project) CreateProjectStructure() error {
6772 }
6873
6974 // Create .gitignore file
70- if err := p .CreateFileFromTemplate (gitignoreTmplPath , projectPath , ".gitignore" ); err != nil {
75+ if err := p .CreateFileFromTemplate (gitignoreTmpl , projectPath , ".gitignore" ); err != nil {
7176 log .Printf ("Error creating .gitignore file: %v\n " , err )
7277 return err
7378 }
7479
7580 // Create main.cpp file
7681 mainPath := filepath .Join (projectPath , srcPath )
77- if err := p .CreateFileFromTemplate (mainTmplPath , mainPath , "main.cpp" ); err != nil {
82+ if err := p .CreateFileFromTemplate (mainTmpl , mainPath , "main.cpp" ); err != nil {
7883 log .Printf ("Error creating main.cpp file: %v\n " , err )
7984 return err
8085 }
@@ -93,9 +98,9 @@ func (p *Project) CreateProjectStructure() error {
9398 return nil
9499}
95100
96- func (p * Project ) CreateFileFromTemplate (tmplPath string , destinationPath string , filename string ) error {
101+ func (p * Project ) CreateFileFromTemplate (tmplContent string , destinationPath string , filename string ) error {
97102 // read template file
98- tmpl , err := template .ParseFiles ( tmplPath )
103+ tmpl , err := template .New ( filename ). Parse ( tmplContent )
99104 if err != nil {
100105 log .Printf ("Error parsing template file: %v\n " , err )
101106 return err
0 commit comments