feat(T-001): 初始化 go 模块 + go-app 最小可运行页面

- go.mod:module lingo,依赖 go-app v10.1.11
- main.go:go-app 装配入口;init() 注册路由(Handler 仅为已注册路由返回
  app shell),newHandler() 抽出便于测试,main() 起 http 服务
- main_test.go:in-process httptest 冒烟测试,验证根路径 200 +
  home 组件预渲染 + wasm 引导脚本注入
- .gitignore:忽略 /bin/ 构建产物
- 06-tasks:T-001 标 DONE;current-state 更新为 Phase 0 进行中、下一任务 T-002

验证:gofmt 干净 · go vet 通过 · go test 通过 · GOOS=js GOARCH=wasm go build 通过 · go build 通过

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ila
2026-06-21 19:45:13 +08:00
co-authored by Claude Opus 4.8
parent 5825d5f677
commit 6e30daceab
7 changed files with 146 additions and 17 deletions
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// TestHandlerServesAppShell 在进程内验证 go-app Handler 能返回 app shell:
// - 根路径返回 200;
// - home 组件被服务端预渲染进 HTML(最小页面可见);
// - 引导 wasm 的脚本(wasm_exec.js / app.js)已注入。
//
// 用 httptest 而非真实网络,避免依赖本机端口。
func TestHandlerServesAppShell(t *testing.T) {
h := newHandler()
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("根路径状态 = %d, 期望 200", rec.Code)
}
body := rec.Body.String()
for _, want := range []string{
`lang="zh"`, // 语言
"走遍美国 · 精听", // home 组件预渲染内容
"/wasm_exec.js", // wasm 运行时
"/app.js", // 加载 app.wasm 的引导脚本
} {
if !strings.Contains(body, want) {
t.Errorf("app shell 未包含 %q", want)
}
}
}