build: use ksrv engine
parent
0aa278efa0
commit
f76cc2f75e
6
app.go
6
app.go
|
@ -112,6 +112,8 @@ func (cui *ConfigUI) App(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
data.File.Content = content
|
||||
|
||||
cui.Parse(w, "home", data)
|
||||
err = cui.tmpl.ExecuteTemplate(w, "home", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
17
configui.go
17
configui.go
|
@ -1,17 +1,16 @@
|
|||
package configui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"kumoly.io/lib/klog"
|
||||
"kumoly.io/lib/ksrv/engine"
|
||||
"kumoly.io/tools/configui/public"
|
||||
)
|
||||
|
||||
|
@ -54,7 +53,7 @@ type ConfigUI struct {
|
|||
LogLevel int `json:"log_level"`
|
||||
|
||||
TmplFS embed.FS `json:"-"`
|
||||
tmpl *template.Template
|
||||
tmpl *engine.Engine
|
||||
PublicFS embed.FS `json:"-"`
|
||||
log *klog.Logger `json:"-"`
|
||||
ksrv_log *klog.Logger `json:"-"`
|
||||
|
@ -62,7 +61,7 @@ type ConfigUI struct {
|
|||
}
|
||||
|
||||
func New() *ConfigUI {
|
||||
tmpl := template.Must(template.New("").Funcs(template.FuncMap{
|
||||
tmpl := engine.Must(engine.New("").Funcs(template.FuncMap{
|
||||
"step": func(from, to, step uint) []uint {
|
||||
items := []uint{}
|
||||
for i := from; i <= to; i += step {
|
||||
|
@ -211,13 +210,3 @@ func (cui *ConfigUI) AppendFile(file *File) error {
|
|||
cui.Files = append(cui.Files, file)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cui *ConfigUI) Parse(w http.ResponseWriter, name string, data interface{}) error {
|
||||
buf := &bytes.Buffer{}
|
||||
err := cui.tmpl.ExecuteTemplate(buf, "home", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = w.Write(buf.Bytes())
|
||||
return err
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -3,8 +3,8 @@ module kumoly.io/tools/configui
|
|||
go 1.17
|
||||
|
||||
require (
|
||||
kumoly.io/lib/klog v0.1.9
|
||||
kumoly.io/lib/ksrv v0.1.4
|
||||
kumoly.io/lib/klog v0.1.10
|
||||
kumoly.io/lib/ksrv v0.1.5-0.20211104040031-77be1d6ae358
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
4
go.sum
4
go.sum
|
@ -4,5 +4,9 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK
|
|||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
kumoly.io/lib/klog v0.1.9 h1:rS9PPqfyBIIfeQlPSuMv+7StGPiFVuAdp04HDwwDY3E=
|
||||
kumoly.io/lib/klog v0.1.9/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
|
||||
kumoly.io/lib/klog v0.1.10 h1:GJxwcsUct8nF3oHtsJPTIlPKTUeB/+7jsbgh3bMvKMc=
|
||||
kumoly.io/lib/klog v0.1.10/go.mod h1:Snm+c1xRrh/RbXsxQf7UGYbAJGPcIa6bEEN+CmzJh7M=
|
||||
kumoly.io/lib/ksrv v0.1.4 h1:8zbslRwdNWHw5Wm1PiyDLr6Mu4xxjz0FTW4u8dZ6ZeI=
|
||||
kumoly.io/lib/ksrv v0.1.4/go.mod h1:eKfhJR5mOqlQZAy5EUI+Avfxirx2/nNW79r+Ki2C18k=
|
||||
kumoly.io/lib/ksrv v0.1.5-0.20211104040031-77be1d6ae358 h1:cVm0fUXzLYZBmhTJf0MRLBt35jLhjodadI8uUh4RNEg=
|
||||
kumoly.io/lib/ksrv v0.1.5-0.20211104040031-77be1d6ae358/go.mod h1:Tux6CApi3sYGRM5prDPN2+aw3gKz1Tdf5CU6XFSFxbQ=
|
||||
|
|
Loading…
Reference in New Issue