31 lines
554 B
Go
31 lines
554 B
Go
|
// utils/utils.go
|
||
|
package utils
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"os"
|
||
|
"text/template"
|
||
|
)
|
||
|
|
||
|
func CreateDirIfNotExists(dir string) error {
|
||
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||
|
return os.MkdirAll(dir, 0755)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func GenerateMarkdown(templatePath string, outputPath string, data map[string]interface{}) error {
|
||
|
tmpl, err := template.ParseFiles(templatePath)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
var output bytes.Buffer
|
||
|
err = tmpl.Execute(&output, data)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return os.WriteFile(outputPath, output.Bytes(), 0644)
|
||
|
}
|