commit a115ec5ce4f5f25298922a8210a6f8fe3ad7ec12
parent 5c9b00bd7309d8690a9f925d5c9341ed11a1b7d8
Author: vasyahacker <vasya@magicfreedom.com>
Date: Fri, 31 Mar 2023 11:35:04 +0400
move templates path to -tpl option
Diffstat:
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/cmd/idecd/main.go b/cmd/idecd/main.go
@@ -10,6 +10,7 @@ import (
"os"
"strings"
"path/filepath"
+ "errors"
"golang.org/x/sys/unix"
)
@@ -61,9 +62,11 @@ var sysname_opt *string = flag.String("sys", "OpenIDEC", "Node name")
var host_opt *string = flag.String("host", "http://127.0.0.1:8080", "Node address")
var verbose_opt *bool = flag.Bool("v", false, "Verbose")
var echo_opt *string = flag.String("e", "list.txt", "Echoes list")
+var tpl_path_opt *string = flag.String("tpl", "./tpl", "Path to html templates")
type WWW struct {
Host string
+ tplp string // templates path
tpl *template.Template
db *ii.DB
edb *ii.EDB
@@ -100,8 +103,12 @@ func main() {
flag.Parse()
- unix.Unveil("./tpl", "r")
- unix.Unveil("/var/openidec/tpl", "r")
+ if _, err := os.Stat(*tpl_path_opt); errors.Is(err, os.ErrNotExist) {
+ ii.Error.Printf("Templates dir %s not found", *tpl_path_opt)
+ os.Exit(1)
+ }
+
+ unix.Unveil(*tpl_path_opt, "r")
unix.Unveil(*echo_opt, "r")
unix.Unveil(*users_opt, "rwc")
unix.Unveil(filepath.Dir(*db_opt), "rwc")
@@ -116,10 +123,11 @@ func main() {
ii.OpenLog(os.Stdout, os.Stdout, os.Stderr)
}
- db.Name = *sysname_opt
- www.db = db
- www.edb = edb
- www.udb = udb
+ db.Name = *sysname_opt
+ www.tplp = *tpl_path_opt
+ www.db = db
+ www.edb = edb
+ www.udb = udb
www.Host = *host_opt
WebInit(&www)
diff --git a/cmd/idecd/web.go b/cmd/idecd/web.go
@@ -913,18 +913,8 @@ func WebInit(www *WWW) {
},
}
- tpl_path := "tpl"
- if _, err := os.Stat(tpl_path); errors.Is(err, os.ErrNotExist) {
- ii.Info.Printf("./tpl not found, trying /var/openidec/tpl..")
- tpl_path = "/var/openidec/tpl"
- if _, err := os.Stat(tpl_path); errors.Is(err, os.ErrNotExist) {
- ii.Error.Printf(" %s not found", tpl_path)
- os.Exit(1)
- }
- }
-
www.tpl = template.Must(
- template.New("main").Funcs(funcMap).ParseGlob(tpl_path + "/*.tpl"))
+ template.New("main").Funcs(funcMap).ParseGlob(www.tplp + "/*.tpl"))
}
func handleErr(ctx *WebContext, w http.ResponseWriter, err error) {