gosp

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: BSD-3-Clause-Clear

README

Go Server Pages

Description

Go Server Pages, or "Gosp" for short, let you embed Go code right in the middle of an HTML document—or in fact any type of document that your Web server can serve. The Web server executes the code and includes its output in the page, right where the code originally appeared. The process is completely invisible to clients, making Go Server Pages 100% compatible with every Web browser in existence.

If you're familiar with PHP or JavaServer Pages, Go Server Pages is just like those but based on the Go programming language.

Example

Here's a trivial example of a Go Server Page:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My first Go Server Page</title>
  </head>

  <body>
    <p>
      I like the number <?go:expr 2*2*2*3*3*5*7 ?> because it's
      divisible by each integer from 1 to 10.
    </p>
  </body>
</html>

The only difference from ordinary HTML in the above is the <?go:expr 2*2*2*3*3*5*7 ?> markup. This tells the Web server to evaluate 2*2*2*3*3*5*7 as a Go expression and replace the markup with the result, producing

I like the number 2520 because it's divisible by each integer from 1 to 10.

in the HTML sent back to the user's Web browser. The user has no way of knowing that 2520 was generated dynamically, not entered statically in the HTML.

See more examples.

Usage

Go Server Pages is designed for simplicity. Only the following new markup is introduced:

Markup Meaning
<?go:expr code ?> Evaluate code as a Go expression
<?go:block code ?> Execute statement or statement block code
<?go:top code ?> Declare file-level code code (import, func, const, etc.)
<?go:include file ?> Include local file file as if it were pasted in

Requirements

Not surprisingly, Go Server Pages requires a Go installation. Go Server Pages currently works only with the Apache Web server.

Documentation

Full documentation can be found at https://gosp.pakin.org/.

Author

Scott Pakin, scott+gosp@pakin.org

Directories

Path Synopsis
Package helper helps demonstrate a Go Server Page's ability to access an external Go package.
Package helper helps demonstrate a Go Server Page's ability to access an external Go package.
src
gosp
Package gosp provides all of the types, functions, and values needed to compile a generated Gosp server.
Package gosp provides all of the types, functions, and values needed to compile a generated Gosp server.
gosp-server command
gosp-server launches a server process that accepts requests on a local socket and sends back metadata followed by data (e.g., HTML).
gosp-server launches a server process that accepts requests on a local socket and sends back metadata followed by data (e.g., HTML).
gosp2go command
gosp2go compiles a Go Server Page to ordinary Go code.
gosp2go compiles a Go Server Page to ordinary Go code.

Jump to

Keyboard shortcuts

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