static

command
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

README

static.png

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>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style><? write("%s", ctx.W3CSS()) ?></style>
    <style>
      .dyd-blue{background-color:#b4c7dc;}
      .dyd-logo {
	      display: inline;color: #ffffff;font-weight: 950;font-style: italic;text-shadow: 2px 2px black;margin-left: 0.5em;
	      -moz-transform: scale(-1, -1);-webkit-transform: scale(-1, -1);-o-transform: scale(-1, -1);
	      -ms-transform: scale(-1, -1);transform: scale(-1, -1);
        }
    </style>
  </head>
  <body class="w3-pale-blue">
    <div class="w3-container w3-padding-small dyd-blue">
      <h3 class="w3-left dyd-logo">php</h3>
      <div class="w3-right"><? write("req #%d for %s at %s", ctx.ReqSequence, ctx.Request.URL, time.Now().Format(time.RFC1123Z)) ?></div>
    </div>
    <div class="w3-container w3-cell">
      <p>Hello!</p>
      <div class="w3-animate-fading"><img src="/images/logo500.png"></div>
    </div>
  </body>
</html>

  • examples/static/dyd.go
// Code generated by dyd, DO NOT EDIT.

package main

import (
	"golang.org/x/net/html"
	"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)
	app.AddMeta("/index.html", []html.Attribute{
		html.Attribute{Namespace: "", Key: "charset", Val: "utf-8"},
	})
	app.AddMeta("/index.html", []html.Attribute{
		html.Attribute{Namespace: "", Key: "name", Val: "viewport"},
		html.Attribute{Namespace: "", Key: "content", Val: "width=device-width, initial-scale=1"},
	})
	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>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>`)
	write("%s", ctx.W3CSS())
	write(`</style>
    <style>
      .dyd-blue{background-color:#b4c7dc;}
      .dyd-logo {
	      display: inline;color: #ffffff;font-weight: 950;font-style: italic;text-shadow: 2px 2px black;margin-left: 0.5em;
	      -moz-transform: scale(-1, -1);-webkit-transform: scale(-1, -1);-o-transform: scale(-1, -1);
	      -ms-transform: scale(-1, -1);transform: scale(-1, -1);
        }
    </style>
  </head>
  <body class="w3-pale-blue">
    <div class="w3-container w3-padding-small dyd-blue">
      <h3 class="w3-left dyd-logo">php</h3>
      <div class="w3-right">`)
	write("req #%d for %s at %s", ctx.ReqSequence, ctx.Request.URL, time.Now().Format(time.RFC1123Z))
	write(`</div>
    </div>
    <div class="w3-container w3-cell">
      <p>Hello!</p>
      <div class="w3-animate-fading"><img src="/images/logo500.png"></div>
    </div>
  </body>
</html>
`)
}

  • examples/static/main.go
package main

import (
	"embed"
	"log"
	"net/http"
)

var (
	//go:embed images
	images embed.FS
)

func main() {
	http.Handle("/images/", http.FileServer(http.FS(images)))
	log.Fatal(dydStart())
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL