Use esc to embed static assets
This commit is contained in:
parent
1d3ad672cb
commit
7226e9f1e2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
chldapasswd
|
chldapasswd
|
||||||
config.json
|
config.json
|
||||||
|
static.go
|
9
main.go
9
main.go
@ -1,5 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate esc -o static.go static
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -12,13 +13,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var StaticDir string = "./static/"
|
|
||||||
|
|
||||||
var myLDAP = LDAP{
|
var myLDAP = LDAP{
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: 389,
|
Port: 389,
|
||||||
@ -70,15 +68,10 @@ func main() {
|
|||||||
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
|
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
|
||||||
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
||||||
var configfile = flag.String("config", "config.json", "path to the configuration file")
|
var configfile = flag.String("config", "config.json", "path to the configuration file")
|
||||||
flag.StringVar(&StaticDir, "static", StaticDir, "Directory containing static files")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Sanitize options
|
// Sanitize options
|
||||||
var err error
|
|
||||||
log.Println("Checking paths...")
|
log.Println("Checking paths...")
|
||||||
if StaticDir, err = filepath.Abs(StaticDir); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if *baseURL != "/" {
|
if *baseURL != "/" {
|
||||||
tmp := path.Clean(*baseURL)
|
tmp := path.Clean(*baseURL)
|
||||||
baseURL = &tmp
|
baseURL = &tmp
|
||||||
|
16
tmpl.go
16
tmpl.go
@ -7,11 +7,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func displayTmpl(w http.ResponseWriter, page string, vars map[string]interface{}) {
|
func displayTmpl(w http.ResponseWriter, page string, vars map[string]interface{}) {
|
||||||
if t, err := template.ParseGlob(path.Join(StaticDir, "*.html")); err != nil {
|
t := template.New("index")
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
for _, fname := range []string{
|
||||||
} else {
|
"/static/change.html",
|
||||||
t.ExecuteTemplate(w, page, vars)
|
"/static/footer.html",
|
||||||
|
"/static/header.html",
|
||||||
|
"/static/login.html",
|
||||||
|
"/static/lost.html",
|
||||||
|
"/static/message.html",
|
||||||
|
"/static/reset.html",
|
||||||
|
} {
|
||||||
|
t.New(path.Base(fname)).Parse(FSMustString(false, fname))
|
||||||
}
|
}
|
||||||
|
t.ExecuteTemplate(w, page, vars)
|
||||||
}
|
}
|
||||||
|
|
||||||
func displayTmplError(w http.ResponseWriter, statusCode int, page string, vars map[string]interface{}) {
|
func displayTmplError(w http.ResponseWriter, statusCode int, page string, vars map[string]interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user