mirror of
https://github.com/golang/go
synced 2024-11-25 02:07:58 -07:00
doc/codelab/wiki: replace curl with a Go program
R=rsc, bradfitzgo CC=golang-dev https://golang.org/cl/4087043
This commit is contained in:
parent
9a9c156a00
commit
9ec785af2f
@ -13,9 +13,9 @@ CLEANFILES+=index.html srcextract.bin htmlify.bin
|
|||||||
index.html: srcextract.bin htmlify.bin
|
index.html: srcextract.bin htmlify.bin
|
||||||
awk '/^!/{system(substr($$0,2)); next} {print}' "$$@" < wiki.html > index.html
|
awk '/^!/{system(substr($$0,2)); next} {print}' "$$@" < wiki.html > index.html
|
||||||
|
|
||||||
test: final.bin
|
test: final.bin get.bin
|
||||||
bash ./test.sh
|
bash ./test.sh
|
||||||
rm -f final.6 final.bin
|
rm -f final.6 final.bin get.6 get.bin
|
||||||
|
|
||||||
%.bin: %.$O
|
%.bin: %.$O
|
||||||
$(LD) -o $@ $<
|
$(LD) -o $@ $<
|
||||||
|
36
doc/codelab/wiki/get.go
Normal file
36
doc/codelab/wiki/get.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"http"
|
||||||
|
"flag"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var post = flag.String("post", "", "urlencoded form data to POST")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
url := flag.Arg(0)
|
||||||
|
if url == "" {
|
||||||
|
log.Exit("no url supplied")
|
||||||
|
}
|
||||||
|
var r *http.Response
|
||||||
|
var err os.Error
|
||||||
|
if *post != "" {
|
||||||
|
b := strings.NewReader(*post)
|
||||||
|
r, err = http.Post(url, "application/x-www-form-urlencoded", b)
|
||||||
|
} else {
|
||||||
|
r, _, err = http.Get(url)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Exit(err)
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
_, err = io.Copy(os.Stdout, r.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Exit(err)
|
||||||
|
}
|
||||||
|
}
|
@ -12,11 +12,11 @@ trap cleanup INT
|
|||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
curl -s -o test_edit.out http://localhost:8080/edit/Test
|
./get.bin http://localhost:8080/edit/Test > test_edit.out
|
||||||
diff -u test_edit.out test_edit.good || cleanup 1
|
diff -u test_edit.out test_edit.good || cleanup 1
|
||||||
curl -s -o /dev/null -d body=some%20content http://localhost:8080/save/Test
|
./get.bin -post=body=some%20content http://localhost:8080/save/Test
|
||||||
diff -u Test.txt test_Test.txt.good || cleanup 1
|
diff -u Test.txt test_Test.txt.good || cleanup 1
|
||||||
curl -s -o test_view.out http://localhost:8080/view/Test
|
./get.bin http://localhost:8080/view/Test > test_view.out
|
||||||
diff -u test_view.out test_view.good || cleanup 1
|
diff -u test_view.out test_view.good || cleanup 1
|
||||||
|
|
||||||
echo "Passed"
|
echo "Passed"
|
||||||
|
Loading…
Reference in New Issue
Block a user