39 lines
709 B
Go
39 lines
709 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
|
|
||
|
"git.akyoto.dev/go/web"
|
||
|
"git.akyoto.dev/go/web/send"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
html := mustLoad("public/app.html")
|
||
|
css := mustLoad("public/app.css")
|
||
|
body := mustLoad("public/body.html")
|
||
|
layout := strings.Replace(html, "%head%", fmt.Sprintf("<style>%s</style>", css), 1)
|
||
|
|
||
|
s := web.NewServer()
|
||
|
|
||
|
s.Get("/", func(ctx web.Context) error {
|
||
|
return send.HTML(ctx, strings.Replace(layout, "%body%", body, 1))
|
||
|
})
|
||
|
|
||
|
s.Run(":8080")
|
||
|
}
|
||
|
|
||
|
func mustLoad(path string) string {
|
||
|
dataBytes, err := os.ReadFile(path)
|
||
|
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
data := string(dataBytes)
|
||
|
data = strings.ReplaceAll(data, "\t", "")
|
||
|
data = strings.ReplaceAll(data, "\n", "")
|
||
|
return data
|
||
|
}
|