template.go 746 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "github.com/valyala/fasttemplate"
  4. "io/ioutil"
  5. )
  6. /*
  7. Web Template Generator
  8. This is the main system core module that perform function similar to what PHP did.
  9. To replace part of the content of any file, use {{paramter}} to replace it.
  10. */
  11. func template_load(filename string, replacement map[string]interface{}) (string, error){
  12. content, err := ioutil.ReadFile(filename)
  13. if (err != nil){
  14. return "", nil
  15. }
  16. t := fasttemplate.New(string(content), "{{", "}}")
  17. s := t.ExecuteString(replacement)
  18. return string(s), nil
  19. }
  20. func template_apply(templateString string, replacement map[string]interface{}) string{
  21. t := fasttemplate.New(templateString, "{{", "}}")
  22. s := t.ExecuteString(replacement)
  23. return string(s)
  24. }