go-gopher/gopher_test.go
2016-09-14 14:32:16 +10:00

31 lines
585 B
Go

package gopher_test
import (
"fmt"
"log"
"github.com/prologic/go-gopher"
)
func hello(w gopher.ResponseWriter, r *gopher.Request) {
w.WriteInfo("Hello World!")
}
func Example_client() {
res, err := gopher.Get("gopher://gopher.floodgap.com")
if err != nil {
log.Fatal(err)
}
fmt.Print(res.Dir.ToText())
}
func Example_server() {
gopher.HandleFunc("/hello", hello)
log.Fatal(gopher.ListenAndServe("localhost:7000", nil))
}
func Example_fileserver() {
gopher.Handle("/", gopher.FileServer(gopher.Dir("/tmp")))
log.Fatal(gopher.ListenAndServe("localhost:7000", nil))
}