Including Go code on a Web page
Once Go Server Pages is installed and configured, Go code can be included on a Web page. This code runs entirely on the server; the client cannot tell that some parts of the Web page are static while others were generated dynamically by executing Go code.
Go code is embedded on a Web page using a set of specialized markup commands. These commands are summarized below:
| 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 |
For details, see the following pages:
- Expressions (
?go:expr … ?>) - Statements (
?go:block … ?>) - Top-level code (
?go:top … ?>) - File inclusion (
?go:include … ?>) - Whitespace removal