github.com/llimllib/devd@v0.0.0-20230426145215-4d29fc25f909/rice-box.go (about)

     1  package devd
     2  
     3  import (
     4  	"github.com/GeertJohan/go.rice/embedded"
     5  	"time"
     6  )
     7  
     8  func init() {
     9  
    10  	// define files
    11  	file2 := &embedded.EmbeddedFile{
    12  		Filename:    "404.html",
    13  		FileModTime: time.Unix(1503017339, 0),
    14  		Content:     string("<html>\n    <head>\n        <style>\n            p {\n                padding: 20px;\n                font-size: 3em;\n            }\n            .footer {\n                width: 100%;\n                margin-top: 2em;\n                text-align: right;\n                font-style: italic;\n            }\n        </style>\n    </head>\n    <body>\n        <p>404: Page not found</p>\n        <div class=\"footer\">\n            {{ .Version }}\n        </div>\n    </body>\n</html>\n"),
    15  	}
    16  	file3 := &embedded.EmbeddedFile{
    17  		Filename:    "dirlist.html",
    18  		FileModTime: time.Unix(1503017339, 0),
    19  		Content:     string("<html>\n    <head>\n        <style>\n            #files {\n                border-collapse: collapse;\n            }\n            .dir a {\n                color: #0741d9;\n            }\n            .file a {\n                color: #0787d9;\n            }\n            .hidden a {\n                color: #a5b1b9;\n            }\n            #files tr {\n                border-bottom: 1px solid #c0c0c0;\n            }\n            #files td {\n                padding: 10px;\n            }\n            #files .dir .name {\n                font-weight: bold\n            }\n            #files .empty {\n                font-style: italic;\n            }\n            .footer {\n                width: 100%;\n                margin-top: 2em;\n                text-align: right;\n                font-style: italic;\n            }\n        </style>\n    </head>\n    <body>\n        <h1>{{.Name}}</h1>\n        <table id=\"files\">\n            {{ range .Files }}\n    \t\t\t<tr class=\"{{ . | fileType  }}\">\n                    <td class=\"name\">\n                        <a href=\"{{.Name}}\">{{.Name}}{{ if .IsDir }}/{{ end }}</a>\n                    </td>\n                    <td class=\"size\">{{ .Size | bytes }}</td>\n                    <td class=\"modified\">{{ .ModTime | reltime }}</td>\n                </tr>\n            {{ else }}\n                <tr><td class=\"empty\" span=\"2\">No files found.</td></tr>\n            {{ end }}\n        </table>\n        <div class=\"footer\">\n            {{ .Version }}\n        </div>\n    </body>\n</html>\n"),
    20  	}
    21  
    22  	// define dirs
    23  	dir1 := &embedded.EmbeddedDir{
    24  		Filename:   "",
    25  		DirModTime: time.Unix(1503017339, 0),
    26  		ChildFiles: []*embedded.EmbeddedFile{
    27  			file2, // "404.html"
    28  			file3, // "dirlist.html"
    29  
    30  		},
    31  	}
    32  
    33  	// link ChildDirs
    34  	dir1.ChildDirs = []*embedded.EmbeddedDir{}
    35  
    36  	// register embeddedBox
    37  	embedded.RegisterEmbeddedBox(`templates`, &embedded.EmbeddedBox{
    38  		Name: `templates`,
    39  		Time: time.Unix(1503017339, 0),
    40  		Dirs: map[string]*embedded.EmbeddedDir{
    41  			"": dir1,
    42  		},
    43  		Files: map[string]*embedded.EmbeddedFile{
    44  			"404.html":     file2,
    45  			"dirlist.html": file3,
    46  		},
    47  	})
    48  }