| 1 |
{{/* |
| 2 |
Usage: |
| 3 |
|
| 4 |
goexample "gocloud.dev/foo.ExampleBar" |
| 5 |
goexample src="gocloud.dev/foo.ExampleBar" |
| 6 |
goexample src="gocloud.dev/foo.ExampleBar" imports="0" |
| 7 |
|
| 8 |
*/ -}} |
| 9 |
{{ if .IsNamedParams -}} |
| 10 |
{{ with index .Site.Data.examples (.Get "src") -}} |
| 11 |
{{ if and .imports (ne ($.Get "imports") "0") -}} |
| 12 |
{{ highlight (printf "%s\n\n%s\n" .imports .code) "go" "" -}} |
| 13 |
{{ else -}} |
| 14 |
{{ highlight (printf "%s\n" .code) "go" "" -}} |
| 15 |
{{ end -}} |
| 16 |
{{ else -}} |
| 17 |
{{ errorf "%s: Example %q does not exist" ($.Page.File.Path) (.Get "src") -}} |
| 18 |
{{end -}} |
| 19 |
{{ else -}} |
| 20 |
{{ with index .Site.Data.examples (.Get 0) -}} |
| 21 |
{{ if .imports -}} |
| 22 |
{{ highlight (printf "%s\n\n%s\n" .imports .code) "go" "" -}} |
| 23 |
{{ else -}} |
| 24 |
{{ highlight (printf "%s\n" .code) "go" "" -}} |
| 25 |
{{ end -}} |
| 26 |
{{ else -}} |
| 27 |
{{ errorf "%s: Example %q does not exist" ($.Page.File.Path) (.Get 0) -}} |
| 28 |
{{end -}} |
| 29 |
{{ end -}} |