From 7860a987603d3a1e29eaec2d28975258dc588205 Mon Sep 17 00:00:00 2001 From: James Mills Date: Wed, 14 Sep 2016 16:23:46 +1000 Subject: [PATCH] Improve hello example with FILE and DIR handlers --- examples/hello/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/hello/main.go b/examples/hello/main.go index 12d8209..fd916b5 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -9,19 +9,31 @@ import ( func index(w gopher.ResponseWriter, r *gopher.Request) { w.WriteItem( gopher.Item{ - Type: gopher.FILE, + Type: gopher.DIRECTORY, Selector: "/hello", Description: "hello", }, ) + w.WriteItem( + gopher.Item{ + Type: gopher.FILE, + Selector: "/foo", + Description: "foo", + }, + ) } func hello(w gopher.ResponseWriter, r *gopher.Request) { w.WriteInfo("Hello World!") } +func foo(w gopher.ResponseWriter, r *gopher.Request) { + w.Write([]byte("Foo!")) +} + func main() { gopher.HandleFunc("/", index) + gopher.HandleFunc("/foo", foo) gopher.HandleFunc("/hello", hello) log.Fatal(gopher.ListenAndServe("localhost:70", nil)) }