package mailer import ( "encoding/json" "os" "clickandjoin.app/emailserver/modules/cache" "clickandjoin.app/emailserver/modules/config" gocnjhelper "git.clickandjoin.umbach.dev/ClickandJoin/go-cnj-helper" "github.com/tdewolff/minify/v2/minify" ) func readTemplatesConfig() { gocnjhelper.LogDebug("START READING TEMPLATE CONFIG") byteValue, err := os.ReadFile(config.Cfg.Templates.ConfigPath) if err != nil { gocnjhelper.LogFatalf("Failed to read config file, err: %s", err) } err = json.Unmarshal(byteValue, &cache.Templates) if err != nil { gocnjhelper.LogFatalf("Failed to unmarshal templates config, err: %s", err) } gocnjhelper.LogDebug("FINISHED READING TEMPLATE CONFIG") } func loadTemplateFiles() { gocnjhelper.LogDebug("STARTING IMPORTING TEMPLATE FILES") for templateName := range cache.Templates.Templates { data, err := os.ReadFile(config.Cfg.Templates.FolderPath + templateName + ".html") if err != nil { gocnjhelper.LogFatalf("Failed to read file, err: %s", err) } minifiedHtml, err := minify.HTML(string(data)) if err != nil { gocnjhelper.LogFatalf("Failed to minify html, err: %s", err) } cache.BodyTemplates[templateName] = []byte(minifiedHtml) } gocnjhelper.LogDebug("FINISHED IMPORTING TEMPLATE FILES") }