0
0
mirror of https://github.com/rls-moe/nyx synced 2025-08-19 06:18:38 +00:00

Embedded Resources

This commit is contained in:
Tim Schuster
2017-03-15 14:33:27 +01:00
parent 477d3477df
commit 37ba7255fe
9 changed files with 257 additions and 43 deletions

View File

@@ -9,26 +9,20 @@ import (
"net/http"
)
var riceConf = rice.Config{
LocateOrder: []rice.LocateMethod{
rice.LocateWorkingDirectory,
rice.LocateEmbedded,
rice.LocateAppended,
},
}
var box = riceConf.MustFindBox("http/errw/res/")
var (
errorTmpl = template.New("errw/error")
)
func init() {
var err error
func LoadTemplates() error {
box, err := rice.FindBox("res/")
if err != nil {
return err
}
errorTmpl, err = errorTmpl.Parse(box.MustString("error.html"))
if err != nil {
panic(err)
return err
}
return nil
}
type ErrorWithTitle interface {

41
http/errw/rice-box.go Normal file
View File

@@ -0,0 +1,41 @@
package errw
import (
"github.com/GeertJohan/go.rice/embedded"
"time"
)
func init() {
// define files
file2 := &embedded.EmbeddedFile{
Filename: `error.html`,
FileModTime: time.Unix(1489238440, 0),
Content: string("<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>{{.Config.Site.Title}} Admin Login</title>\n <style>\n div.error {\n border: 1px solid black;\n width: 500px;\n margin: auto;\n margin-top: 100px;\n }\n div.error h1 {\n margin-bottom: 0px;\n text-align: center;\n }\n div.error h2 {\n text-align: center;\n }\n div.error h3 {\n margin-top: 0px;\n text-align: center;\n color: #888;\n }\n </style>\n</head>\n<body>\n<div class=\"error\">\n <h1>{{.Error.Title}}</h1><br/>\n <h3>{{.Error.Code}}</h3><br/>\n <h2>{{.Error.Description}}</h2>\n</div>\n</body>\n</html>"),
}
// define dirs
dir1 := &embedded.EmbeddedDir{
Filename: ``,
DirModTime: time.Unix(1489240168, 0),
ChildFiles: []*embedded.EmbeddedFile{
file2, // error.html
},
}
// link ChildDirs
dir1.ChildDirs = []*embedded.EmbeddedDir{}
// register embeddedBox
embedded.RegisterEmbeddedBox(`res/`, &embedded.EmbeddedBox{
Name: `res/`,
Time: time.Unix(1489240168, 0),
Dirs: map[string]*embedded.EmbeddedDir{
"": dir1,
},
Files: map[string]*embedded.EmbeddedFile{
"error.html": file2,
},
})
}