39 lines
966 B
Go
39 lines
966 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
|
|
|
|
//go:embed static/helpers.js
|
|
var helpersJS []byte
|
|
|
|
//go:embed static/batch.js
|
|
var batchJS []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)
|
|
// JS 顺序敏感: app 先声明 consts / 注册 handlers; helpers 后注入纯函数;
|
|
// batch 最后使用 consts 并启动 boot. 同 <script> 内共享顶层 var.
|
|
combined := string(appJS) + "\n" + string(helpersJS) + "\n" + string(batchJS)
|
|
s = strings.Replace(s, "/*EMBED_JS*/", combined, 1)
|
|
pageHTML = []byte(s)
|
|
}
|