Golang, export html files with package

Viewed 82

I'm making a lib with a few templates and a parser which looks like this:

func ParseTemplate(templateFileName string, data interface{}) (string, error) {
    if templateFileName == "" {
        templateFileName = "default_template.html"
    }
    _, b, _, _ := runtime.Caller(0)
    basepath   := filepath.Dir(b)
    filePath := path.Join(basepath, "templates", templateFileName)
    t, err := template.ParseFiles(filePath)
    if err != nil {
        return "", err
    }
    buf := new(bytes.Buffer)
    if err = t.Execute(buf, data); err != nil {
        return "", err
    }
    body := buf.String()
    return body, nil
}

I have a folder called templates which has all the .html files, however, when I try to import the lib in another project, it doesn't include the templates folder with the html... any idea how to have them include or pre-compiled?

0 Answers
Related