setting default cache time super low to test cache expirations
This commit is contained in:
parent
41800f1a13
commit
a72b54a114
29
servlet/templates.go
Normal file
29
servlet/templates.go
Normal file
@ -0,0 +1,29 @@
|
||||
package servlet
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func RenderTemplate(w http.ResponseWriter, pathlike string, data any) {
|
||||
templateHelper := template.New(pathlike)
|
||||
f, err := os.OpenFile(pathlike, os.O_RDONLY, 0777)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
content, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templ, err := templateHelper.Parse(string(content))
|
||||
err = templ.Execute(w, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,33 +3,10 @@ package vinegarUtil
|
||||
import (
|
||||
"bytes"
|
||||
gzip2 "compress/gzip"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func RenderTemplate(w http.ResponseWriter, pathlike string, data any) {
|
||||
templateHelper := template.New(pathlike)
|
||||
f, err := os.OpenFile(pathlike, os.O_RDONLY, 0777)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
content, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templ, err := templateHelper.Parse(string(content))
|
||||
err = templ.Execute(w, data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetDiskContent(filePath string) (*[]byte, bool) {
|
||||
_, ferr := os.Stat(filePath)
|
||||
if os.IsNotExist(ferr) {
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultCacheTimeInMinutes = 15
|
||||
DefaultCacheTimeInMinutes = 1
|
||||
)
|
||||
|
||||
type (
|
||||
Loading…
Reference in New Issue
Block a user