You can execute the example by running $ dyd -serve
in this directory and
pointing your browser to http://localhost:6226.
To only convert the example into a go install-able repository issue $ dyd
.
In either case here are the files after running dyd:
examples/static/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>dyd static example</title>
</head>
<body>
<img src="/static/images/logo500.png">
<p>
Hello world!
<p>
<? write("req #%d for %s at %s", ctx.ReqSequence, ctx.Request.URL, time.Now().Format(time.RFC1123Z)) ?>
</body>
</html>
// Code generated by dyd, DO NOT EDIT.
package main
import (
"modernc.org/dyd/dyd"
)
// dydStart starts the webapp. dydStart always returns a non-nil error.
func dydStart() error {
app, err := dyd.NewApp()
if err != nil {
return err
}
app.Bind("/index.html", Serve_index_1html)
return app.ListenAndServe(":6226")
}
examples/static/index.html.go
// Code generated by dyd, DO NOT EDIT.
package main
import (
"time"
"modernc.org/dyd/dyd"
)
// Serve_index_1html produces /index.html.
func Serve_index_1html(ctx *dyd.Context, write func(s string, args ...any) error) {
write(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>dyd static example</title>
</head>
<body>
<img src="/static/images/logo500.png">
<p>
Hello world!
<p>
`)
write("req #%d for %s at %s", ctx.ReqSequence, ctx.Request.URL, time.Now().Format(time.RFC1123Z))
write(`
</body>
</html>
`)
}
package main
import (
"embed"
"log"
"net/http"
)
var (
//go:embed images
content embed.FS
)
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(content))))
log.Fatal(dydStart())
}