30 lines
625 B
Go
30 lines
625 B
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
_ "embed"
|
|
)
|
|
|
|
// 嵌入式静态页面 (单文件部署, 把 HTML/CSS/JS 编译进二进制, 无需运行时外部文件)
|
|
|
|
//go:embed static/index.html.tpl
|
|
var indexTpl []byte
|
|
|
|
//go:embed static/app.css
|
|
var appCSS []byte
|
|
|
|
//go:embed static/app.js
|
|
var appJS []byte
|
|
|
|
// pageHTML is the assembled single-file deployment response.
|
|
// Computed once at startup; same bytes served on every GET /.
|
|
var pageHTML []byte
|
|
|
|
func init() {
|
|
s := string(indexTpl)
|
|
s = strings.Replace(s, "/*EMBED_CSS*/", string(appCSS), 1)
|
|
s = strings.Replace(s, "/*EMBED_JS*/", string(appJS), 1)
|
|
pageHTML = []byte(s)
|
|
}
|