-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrivial-top.html
53 lines (47 loc) · 1.39 KB
/
trivial-top.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<title>Embedding top-level Go code</title>
<style>
/*<![CDATA[*/
.hello {
border: thin solid black;
padding: 0.5ex;
color: inherit;
background-color: yellow;
}
blockquote {
width: 22em;
color: black;
background-color: #f0f0f0;
padding: 1ex;
}
/*]]>*/
</style>
<?go:top
import (
"fmt"
"io"
)
func SayHelloFrom(w io.Writer, whom string) {
fmt.Fprintf(w, "Hello from %s!", whom)
}
?></head>
<body>
<p>Top-level Go code (<code>import</code>, <code>func</code>, etc.) must be
enclosed within
a <code><?go:top</code> … <code>?></code> tag.
Anything declared top-level will be available
within <code><?go:block</code> … <code>?></code>
and <code><?go:expr</code> … <code>?></code> tags on
the same page.</p>
<blockquote>
I just wanted to say, <q><span class="hello"><?go:block SayHelloFrom(gospOut, "Go Server Pages") ?></span></q>
</blockquote>
<p>In this example, we placed
the <code><?go:top</code> … <code>?></code> tag in the
HTML <code><head></code> … <code></head></code>
section, but this is not mandatory. It can appear anywhere on the
page.</p>
</body>
</html>