Improve hello example with FILE and DIR handlers
This commit is contained in:
parent
58ccb9172e
commit
7860a98760
@ -9,19 +9,31 @@ import (
|
|||||||
func index(w gopher.ResponseWriter, r *gopher.Request) {
|
func index(w gopher.ResponseWriter, r *gopher.Request) {
|
||||||
w.WriteItem(
|
w.WriteItem(
|
||||||
gopher.Item{
|
gopher.Item{
|
||||||
Type: gopher.FILE,
|
Type: gopher.DIRECTORY,
|
||||||
Selector: "/hello",
|
Selector: "/hello",
|
||||||
Description: "hello",
|
Description: "hello",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
w.WriteItem(
|
||||||
|
gopher.Item{
|
||||||
|
Type: gopher.FILE,
|
||||||
|
Selector: "/foo",
|
||||||
|
Description: "foo",
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hello(w gopher.ResponseWriter, r *gopher.Request) {
|
func hello(w gopher.ResponseWriter, r *gopher.Request) {
|
||||||
w.WriteInfo("Hello World!")
|
w.WriteInfo("Hello World!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func foo(w gopher.ResponseWriter, r *gopher.Request) {
|
||||||
|
w.Write([]byte("Foo!"))
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
gopher.HandleFunc("/", index)
|
gopher.HandleFunc("/", index)
|
||||||
|
gopher.HandleFunc("/foo", foo)
|
||||||
gopher.HandleFunc("/hello", hello)
|
gopher.HandleFunc("/hello", hello)
|
||||||
log.Fatal(gopher.ListenAndServe("localhost:70", nil))
|
log.Fatal(gopher.ListenAndServe("localhost:70", nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user