summaryrefslogtreecommitdiff
path: root/doc/articles/wiki/final.go
diff options
context:
space:
mode:
Diffstat (limited to 'doc/articles/wiki/final.go')
-rw-r--r--doc/articles/wiki/final.go23
1 files changed, 23 insertions, 0 deletions
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)
}