initial generation for play.golang.org linking, ref #37
This commit is contained in:
parent
0c18c9689a
commit
056d0aff68
@ -68,7 +68,7 @@ func main() {
|
||||
|
||||
// Now let's look at decoding JSON data into Go
|
||||
// values. Here's an example for a generic data
|
||||
// structure.
|
||||
// structure.
|
||||
byt := []byte(`{"num":6.0,"strs":["a","b"]}`)
|
||||
|
||||
// We need to provide a variable where the JSON
|
||||
|
@ -69,7 +69,7 @@ func main() {
|
||||
// The `bufio` package implements a buffered
|
||||
// reader that may be useful both for its efficiency
|
||||
// with many small reads and because of the additional
|
||||
// reading methods it provides.
|
||||
// reading methods it provides.
|
||||
r4 := bufio.NewReader(f)
|
||||
b4, err := r4.Peek(5)
|
||||
check(err)
|
||||
|
@ -27,7 +27,7 @@ func main() {
|
||||
|
||||
// In addition to these basic operations, slices
|
||||
// support several more that make them richer than
|
||||
// arrays. One is the builtin `append`, which
|
||||
// arrays. One is the builtin `append`, which
|
||||
// returns a slice containing one or more new values.
|
||||
// Note that we need to accept a return value from
|
||||
// append as we may get a new slice value.
|
||||
|
@ -9,7 +9,7 @@ import "strings"
|
||||
|
||||
func main() {
|
||||
|
||||
// We'll parse this example URL, which includes a
|
||||
// We'll parse this example URL, which includes a
|
||||
// scheme, authentication info, host, port, path,
|
||||
// query params, and query fragment.
|
||||
s := "postgres://user:pass@host.com:5432/path?k=v#f"
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="arrays">
|
||||
<h2><a href="./">Go by Example</a>: Arrays</h2>
|
||||
<a href="http://play.golang.org/p/l-A8eBnwio"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="atomic-counters">
|
||||
<h2><a href="./">Go by Example</a>: Atomic Counters</h2>
|
||||
<a href="http://play.golang.org/p/sKIaNsJquU"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="base64-encoding">
|
||||
<h2><a href="./">Go by Example</a>: Base64 Encoding</h2>
|
||||
<a href="http://play.golang.org/p/t6rFm2x4Yr"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="channel-buffering">
|
||||
<h2><a href="./">Go by Example</a>: Channel Buffering</h2>
|
||||
<a href="http://play.golang.org/p/34PVHwO6Bn"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="channel-directions">
|
||||
<h2><a href="./">Go by Example</a>: Channel Directions</h2>
|
||||
<a href="http://play.golang.org/p/P9Fujfpa1f"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="channel-synchronization">
|
||||
<h2><a href="./">Go by Example</a>: Channel Synchronization</h2>
|
||||
<a href="http://play.golang.org/p/0DfW-1RMqi"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="channels">
|
||||
<h2><a href="./">Go by Example</a>: Channels</h2>
|
||||
<a href="http://play.golang.org/p/aVTMoY5FNt"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="closing-channels">
|
||||
<h2><a href="./">Go by Example</a>: Closing Channels</h2>
|
||||
<a href="http://play.golang.org/p/eFZ2SeKswH"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="closures">
|
||||
<h2><a href="./">Go by Example</a>: Closures</h2>
|
||||
<a href="http://play.golang.org/p/gQtEWkhWyp"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="collection-functions">
|
||||
<h2><a href="./">Go by Example</a>: Collection Functions</h2>
|
||||
<a href="http://play.golang.org/p/3PNdke3Wia"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="command-line-arguments">
|
||||
<h2><a href="./">Go by Example</a>: Command-Line Arguments</h2>
|
||||
<a href="http://play.golang.org/p/44uyYt_TRl"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="command-line-flags">
|
||||
<h2><a href="./">Go by Example</a>: Command-Line Flags</h2>
|
||||
<a href="http://play.golang.org/p/9xlvGqQjhl"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="constants">
|
||||
<h2><a href="./">Go by Example</a>: Constants</h2>
|
||||
<a href="http://play.golang.org/p/T5sj0eINnp"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="defer">
|
||||
<h2><a href="./">Go by Example</a>: Defer</h2>
|
||||
<a href="http://play.golang.org/p/9aoHwzHcAo"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="environment-variables">
|
||||
<h2><a href="./">Go by Example</a>: Environment Variables</h2>
|
||||
<a href="http://play.golang.org/p/kfqLhpmEpw"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="epoch">
|
||||
<h2><a href="./">Go by Example</a>: Epoch</h2>
|
||||
<a href="http://play.golang.org/p/3jXHvYbLUz"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="errors">
|
||||
<h2><a href="./">Go by Example</a>: Errors</h2>
|
||||
<a href="http://play.golang.org/p/BmDQXkPPTk"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="execing-processes">
|
||||
<h2><a href="./">Go by Example</a>: Exec'ing Processes</h2>
|
||||
<a href="http://play.golang.org/p/iEAD2cYC-h"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="exit">
|
||||
<h2><a href="./">Go by Example</a>: Exit</h2>
|
||||
<a href="http://play.golang.org/p/CDiAh9SXRM"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="for">
|
||||
<h2><a href="./">Go by Example</a>: For</h2>
|
||||
<a href="http://play.golang.org/p/mGqqcBZ0jv"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="functions">
|
||||
<h2><a href="./">Go by Example</a>: Functions</h2>
|
||||
<a href="http://play.golang.org/p/2EXoOWfGf_"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="goroutines">
|
||||
<h2><a href="./">Go by Example</a>: Goroutines</h2>
|
||||
<a href="http://play.golang.org/p/aIO_Wi3hJj"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="hello-world">
|
||||
<h2><a href="./">Go by Example</a>: Hello World</h2>
|
||||
<a href="http://play.golang.org/p/H8bxSpw9Jq"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="if-else">
|
||||
<h2><a href="./">Go by Example</a>: If/Else</h2>
|
||||
<a href="http://play.golang.org/p/p_ykufAYRj"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="interfaces">
|
||||
<h2><a href="./">Go by Example</a>: Interfaces</h2>
|
||||
<a href="http://play.golang.org/p/vx8bwC-Bmq"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="json">
|
||||
<h2><a href="./">Go by Example</a>: JSON</h2>
|
||||
<a href="http://play.golang.org/p/4L2wMVv7tW"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="line-filters">
|
||||
<h2><a href="./">Go by Example</a>: Line Filters</h2>
|
||||
<a href="http://play.golang.org/p/OSS71nSpkV"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="maps">
|
||||
<h2><a href="./">Go by Example</a>: Maps</h2>
|
||||
<a href="http://play.golang.org/p/D-F9YN_V8r"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="methods">
|
||||
<h2><a href="./">Go by Example</a>: Methods</h2>
|
||||
<a href="http://play.golang.org/p/254m_9Yjwa"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="multiple-return-values">
|
||||
<h2><a href="./">Go by Example</a>: Multiple Return Values</h2>
|
||||
<a href="http://play.golang.org/p/LrDt1Wah0M"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="mutexes">
|
||||
<h2><a href="./">Go by Example</a>: Mutexes</h2>
|
||||
<a href="http://play.golang.org/p/-_LKNceBru"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="non-blocking-channel-operations">
|
||||
<h2><a href="./">Go by Example</a>: Non-Blocking Channel Operations</h2>
|
||||
<a href="http://play.golang.org/p/M972dltae2"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="number-parsing">
|
||||
<h2><a href="./">Go by Example</a>: Number Parsing</h2>
|
||||
<a href="http://play.golang.org/p/N90EppECFk"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="panic">
|
||||
<h2><a href="./">Go by Example</a>: Panic</h2>
|
||||
<a href="http://play.golang.org/p/c86oXzfQOt"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="pointers">
|
||||
<h2><a href="./">Go by Example</a>: Pointers</h2>
|
||||
<a href="http://play.golang.org/p/KdE4TBbUL2"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="random-numbers">
|
||||
<h2><a href="./">Go by Example</a>: Random Numbers</h2>
|
||||
<a href="http://play.golang.org/p/C0_kuFx3ET"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="range">
|
||||
<h2><a href="./">Go by Example</a>: Range</h2>
|
||||
<a href="http://play.golang.org/p/Ys3V-ohVRy"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="range-over-channels">
|
||||
<h2><a href="./">Go by Example</a>: Range over Channels</h2>
|
||||
<a href="http://play.golang.org/p/WN7NNh9tvh"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="rate-limiting">
|
||||
<h2><a href="./">Go by Example</a>: Rate Limiting</h2>
|
||||
<a href="http://play.golang.org/p/e7yzIk97-p"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="reading-files">
|
||||
<h2><a href="./">Go by Example</a>: Reading Files</h2>
|
||||
<a href="http://play.golang.org/p/VcLqpSwnkN"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="recursion">
|
||||
<h2><a href="./">Go by Example</a>: Recursion</h2>
|
||||
<a href="http://play.golang.org/p/RFn-rf42ap"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="regular-expressions">
|
||||
<h2><a href="./">Go by Example</a>: Regular Expressions</h2>
|
||||
<a href="http://play.golang.org/p/7bnr2EXlxK"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="select">
|
||||
<h2><a href="./">Go by Example</a>: Select</h2>
|
||||
<a href="http://play.golang.org/p/NGSkDrli6L"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="sha1-hashes">
|
||||
<h2><a href="./">Go by Example</a>: SHA1 Hashes</h2>
|
||||
<a href="http://play.golang.org/p/YUaWWEeB4U"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="signals">
|
||||
<h2><a href="./">Go by Example</a>: Signals</h2>
|
||||
<a href="http://play.golang.org/p/d42wO1q1oh"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="slices">
|
||||
<h2><a href="./">Go by Example</a>: Slices</h2>
|
||||
<a href="http://play.golang.org/p/dPQErsP6Yc"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="sorting">
|
||||
<h2><a href="./">Go by Example</a>: Sorting</h2>
|
||||
<a href="http://play.golang.org/p/roQOJXtqAb"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="sorting-by-functions">
|
||||
<h2><a href="./">Go by Example</a>: Sorting by Functions</h2>
|
||||
<a href="http://play.golang.org/p/M06NADP985"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="spawning-processes">
|
||||
<h2><a href="./">Go by Example</a>: Spawning Processes</h2>
|
||||
<a href="http://play.golang.org/p/utd_H-XJtC"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="stateful-goroutines">
|
||||
<h2><a href="./">Go by Example</a>: Stateful Goroutines</h2>
|
||||
<a href="http://play.golang.org/p/2YrrJo4H6W"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="string-formatting">
|
||||
<h2><a href="./">Go by Example</a>: String Formatting</h2>
|
||||
<a href="http://play.golang.org/p/qayRuqXHym"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="string-functions">
|
||||
<h2><a href="./">Go by Example</a>: String Functions</h2>
|
||||
<a href="http://play.golang.org/p/COXm374QWe"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="structs">
|
||||
<h2><a href="./">Go by Example</a>: Structs</h2>
|
||||
<a href="http://play.golang.org/p/OMCP5KFC10"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="switch">
|
||||
<h2><a href="./">Go by Example</a>: Switch</h2>
|
||||
<a href="http://play.golang.org/p/8b5CajPcHn"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="tickers">
|
||||
<h2><a href="./">Go by Example</a>: Tickers</h2>
|
||||
<a href="http://play.golang.org/p/U0PO7ZZU3l"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="time">
|
||||
<h2><a href="./">Go by Example</a>: Time</h2>
|
||||
<a href="http://play.golang.org/p/NxuQTlVA2l"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="time-formatting-parsing">
|
||||
<h2><a href="./">Go by Example</a>: Time Formatting / Parsing</h2>
|
||||
<a href="http://play.golang.org/p/JqNGqbuqF1"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="timeouts">
|
||||
<h2><a href="./">Go by Example</a>: Timeouts</h2>
|
||||
<a href="http://play.golang.org/p/CoBnJiRyx3"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="timers">
|
||||
<h2><a href="./">Go by Example</a>: Timers</h2>
|
||||
<a href="http://play.golang.org/p/6fSHrYxpMu"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="url-parsing">
|
||||
<h2><a href="./">Go by Example</a>: URL Parsing</h2>
|
||||
<a href="http://play.golang.org/p/eaMv0skOfY"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="values">
|
||||
<h2><a href="./">Go by Example</a>: Values</h2>
|
||||
<a href="http://play.golang.org/p/fgGVOyuZdu"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="variables">
|
||||
<h2><a href="./">Go by Example</a>: Variables</h2>
|
||||
<a href="http://play.golang.org/p/Zv45CSMaiD"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="variadic-functions">
|
||||
<h2><a href="./">Go by Example</a>: Variadic Functions</h2>
|
||||
<a href="http://play.golang.org/p/wRPLOM1VIH"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="worker-pools">
|
||||
<h2><a href="./">Go by Example</a>: Worker Pools</h2>
|
||||
<a href="http://play.golang.org/p/y12QxBsKtT"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
<body>
|
||||
<div class="example" id="writing-files">
|
||||
<h2><a href="./">Go by Example</a>: Writing Files</h2>
|
||||
<a href="http://play.golang.org/p/5usz1Oc-xY"><img height="16" width="16" title="Run code" src="play.png" style="float:right" /></a>
|
||||
|
||||
<table>
|
||||
|
||||
|
@ -124,24 +124,24 @@ type Seg struct {
|
||||
}
|
||||
|
||||
type Example struct {
|
||||
Id, Name string
|
||||
GoCode, GoCodeHash, UrlHash string
|
||||
Segs [][]*Seg
|
||||
NextExample *Example
|
||||
Id, Name string
|
||||
GoCode, GoCodeHash, UrlHash string
|
||||
Segs [][]*Seg
|
||||
NextExample *Example
|
||||
}
|
||||
|
||||
func parseHashFile(sourcePath string) (string, string) {
|
||||
var codehash,urlkey string
|
||||
var codehash, urlkey string
|
||||
lines := readLines(sourcePath)
|
||||
for idx,line := range lines {
|
||||
switch idx {
|
||||
case 0:
|
||||
codehash = line
|
||||
case 1:
|
||||
urlkey = line
|
||||
}
|
||||
for idx, line := range lines {
|
||||
switch idx {
|
||||
case 0:
|
||||
codehash = line
|
||||
case 1:
|
||||
urlkey = line
|
||||
}
|
||||
}
|
||||
return codehash,urlkey
|
||||
return codehash, urlkey
|
||||
}
|
||||
|
||||
func resetUrlHashFile(codehash, code, sourcePath string) string {
|
||||
@ -153,8 +153,8 @@ func resetUrlHashFile(codehash, code, sourcePath string) string {
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
urlkey := string(body)
|
||||
data := fmt.Sprintf("%s\n%s",codehash,urlkey)
|
||||
ioutil.WriteFile(sourcePath,[]byte(data),0644)
|
||||
data := fmt.Sprintf("%s\n%s", codehash, urlkey)
|
||||
ioutil.WriteFile(sourcePath, []byte(data), 0644)
|
||||
return urlkey
|
||||
}
|
||||
|
||||
@ -203,25 +203,25 @@ func parseSegs(sourcePath string) ([]*Seg, string) {
|
||||
seg.CodeEmpty = (seg.Code == "")
|
||||
seg.CodeLeading = (i < (len(segs) - 1))
|
||||
}
|
||||
return segs,filecontent
|
||||
return segs, filecontent
|
||||
}
|
||||
|
||||
func parseAndRenderSegs(sourcePath string) ([]*Seg, string) {
|
||||
segs,filecontent := parseSegs(sourcePath)
|
||||
segs, filecontent := parseSegs(sourcePath)
|
||||
lexer := whichLexer(sourcePath)
|
||||
for _, seg := range segs {
|
||||
if seg.Docs != "" {
|
||||
seg.DocsRendered = markdown(seg.Docs)
|
||||
}
|
||||
if seg.Code != "" {
|
||||
seg.CodeRendered = cachedPygmentize(lexer, seg.Code)
|
||||
}
|
||||
if seg.Docs != "" {
|
||||
seg.DocsRendered = markdown(seg.Docs)
|
||||
}
|
||||
if seg.Code != "" {
|
||||
seg.CodeRendered = cachedPygmentize(lexer, seg.Code)
|
||||
}
|
||||
}
|
||||
// we are only interested in the 'go' code to pass to play.golang.org
|
||||
if lexer != "go" {
|
||||
filecontent = ""
|
||||
}
|
||||
return segs,filecontent
|
||||
filecontent = ""
|
||||
}
|
||||
return segs, filecontent
|
||||
}
|
||||
|
||||
func parseExamples() []*Example {
|
||||
@ -239,21 +239,21 @@ func parseExamples() []*Example {
|
||||
example.Segs = make([][]*Seg, 0)
|
||||
sourcePaths := mustGlob("examples/" + exampleId + "/*")
|
||||
for _, sourcePath := range sourcePaths {
|
||||
switch strings.HasSuffix(sourcePath,".hash") {
|
||||
case true:
|
||||
example.GoCodeHash,example.UrlHash = parseHashFile(sourcePath)
|
||||
default:
|
||||
sourceSegs,filecontents := parseAndRenderSegs(sourcePath)
|
||||
if (filecontents != "") {
|
||||
example.GoCode = filecontents
|
||||
}
|
||||
example.Segs = append(example.Segs, sourceSegs)
|
||||
}
|
||||
switch strings.HasSuffix(sourcePath, ".hash") {
|
||||
case true:
|
||||
example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath)
|
||||
default:
|
||||
sourceSegs, filecontents := parseAndRenderSegs(sourcePath)
|
||||
if filecontents != "" {
|
||||
example.GoCode = filecontents
|
||||
}
|
||||
example.Segs = append(example.Segs, sourceSegs)
|
||||
}
|
||||
}
|
||||
newCodeHash := sha1Sum(example.GoCode)
|
||||
if example.GoCodeHash != newCodeHash {
|
||||
example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.Id+"/"+example.Id+".hash")
|
||||
}
|
||||
newCodeHash := sha1Sum(example.GoCode)
|
||||
if (example.GoCodeHash != newCodeHash) {
|
||||
example.UrlHash = resetUrlHashFile(newCodeHash,example.GoCode,"examples/"+example.Id+"/"+ example.Id + ".hash")
|
||||
}
|
||||
examples = append(examples, &example)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user