summaryrefslogtreecommitdiff
path: root/doc/articles/wiki
diff options
context:
space:
mode:
Diffstat (limited to 'doc/articles/wiki')
-rw-r--r--doc/articles/wiki/Makefile10
-rw-r--r--doc/articles/wiki/final.go23
-rw-r--r--doc/articles/wiki/index.html2
-rwxr-xr-xdoc/articles/wiki/test.bash26
4 files changed, 44 insertions, 17 deletions
diff --git a/doc/articles/wiki/Makefile b/doc/articles/wiki/Makefile
deleted file mode 100644
index e40b1311e..000000000
--- a/doc/articles/wiki/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-all: index.html
-
-CLEANFILES:=get.bin final-test.bin a.out
-
-clean:
- rm -f $(CLEANFILES)
diff --git a/doc/articles/wiki/final.go b/doc/articles/wiki/final.go
index f15794d66..d84c1ffb2 100644
--- a/doc/articles/wiki/final.go
+++ b/doc/articles/wiki/final.go
@@ -5,12 +5,19 @@
package main
import (
+ "flag"
"html/template"
"io/ioutil"
+ "log"
+ "net"
"net/http"
"regexp"
)
+var (
+ addr = flag.Bool("addr", false, "find open address and print to final-port.txt")
+)
+
type Page struct {
Title string
Body []byte
@@ -81,8 +88,24 @@ func makeHandler(fn func(http.ResponseWriter, *http.Request, string)) http.Handl
}
func main() {
+ flag.Parse()
http.HandleFunc("/view/", makeHandler(viewHandler))
http.HandleFunc("/edit/", makeHandler(editHandler))
http.HandleFunc("/save/", makeHandler(saveHandler))
+
+ if *addr {
+ l, err := net.Listen("tcp", "127.0.0.1:0")
+ if err != nil {
+ log.Fatal(err)
+ }
+ err = ioutil.WriteFile("final-port.txt", []byte(l.Addr().String()), 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+ s := &http.Server{}
+ s.Serve(l)
+ return
+ }
+
http.ListenAndServe(":8080", nil)
}
diff --git a/doc/articles/wiki/index.html b/doc/articles/wiki/index.html
index 7bf7213e8..b6b080df9 100644
--- a/doc/articles/wiki/index.html
+++ b/doc/articles/wiki/index.html
@@ -466,7 +466,7 @@ header to the HTTP response.
<p>
The function <code>saveHandler</code> will handle the submission of forms
located on the edit pages. After uncommenting the related line in
-<code>main</code>, let's implement the the handler:
+<code>main</code>, let's implement the handler:
</p>
{{code "doc/articles/wiki/final-template.go" `/^func saveHandler/` `/^}/`}}
diff --git a/doc/articles/wiki/test.bash b/doc/articles/wiki/test.bash
index 54a632c30..2997f1680 100755
--- a/doc/articles/wiki/test.bash
+++ b/doc/articles/wiki/test.bash
@@ -7,10 +7,12 @@ set -e
wiki_pid=
cleanup() {
kill $wiki_pid
- rm -f test_*.out Test.txt final-test.bin final-test.go a.out get.bin
+ rm -f test_*.out Test.txt final.bin final-port.txt a.out get.bin
}
trap cleanup 0 INT
+rm -f get.bin final.bin a.out
+
# If called with -all, check that all code snippets compile.
if [ "$1" == "-all" ]; then
for fn in *.go; do
@@ -19,13 +21,25 @@ if [ "$1" == "-all" ]; then
fi
go build -o get.bin get.go
-addr=$(./get.bin -addr)
-sed s/:8080/$addr/ < final.go > final-test.go
-go build -o final-test.bin final-test.go
-(./final-test.bin) &
+go build -o final.bin final.go
+(./final.bin --addr) &
wiki_pid=$!
-./get.bin --wait_for_port=5s http://$addr/edit/Test > test_edit.out
+l=0
+while [ ! -f ./final-port.txt ]
+do
+ l=$(($l+1))
+ if [ "$l" -gt 5 ]
+ then
+ echo "port not available within 5 seconds"
+ exit 1
+ break
+ fi
+ sleep 1
+done
+
+addr=$(cat final-port.txt)
+./get.bin http://$addr/edit/Test > test_edit.out
diff -u test_edit.out test_edit.good
./get.bin -post=body=some%20content http://$addr/save/Test > test_save.out
diff -u test_save.out test_view.good # should be the same as viewing