2016-09-14 03:45:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2017-02-13 08:18:27 +00:00
|
|
|
"sync"
|
2016-09-14 03:45:49 +00:00
|
|
|
|
2021-07-12 13:54:10 +00:00
|
|
|
"git.mills.io/prologic/go-gopher"
|
2016-09-14 03:45:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func index(w gopher.ResponseWriter, r *gopher.Request) {
|
2018-04-16 02:48:30 +00:00
|
|
|
w.WriteItem(&gopher.Item{
|
|
|
|
Type: gopher.DIRECTORY,
|
|
|
|
Selector: "/hello",
|
|
|
|
Description: "hello",
|
2017-02-13 08:18:27 +00:00
|
|
|
|
2018-04-16 02:48:30 +00:00
|
|
|
// TLS Resource
|
|
|
|
Host: "localhost",
|
|
|
|
Port: 73,
|
|
|
|
Extras: []string{"TLS"},
|
|
|
|
})
|
|
|
|
w.WriteItem(&gopher.Item{
|
|
|
|
Type: gopher.FILE,
|
|
|
|
Selector: "/foo",
|
|
|
|
Description: "foo",
|
|
|
|
})
|
|
|
|
w.WriteItem(&gopher.Item{
|
|
|
|
Type: gopher.DIRECTORY,
|
|
|
|
Selector: "/",
|
|
|
|
Description: "Floodgap",
|
|
|
|
Host: "gopher.floodgap.com",
|
|
|
|
Port: 70,
|
|
|
|
})
|
2016-09-14 03:45:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hello(w gopher.ResponseWriter, r *gopher.Request) {
|
|
|
|
w.WriteInfo("Hello World!")
|
|
|
|
}
|
|
|
|
|
2016-09-14 06:23:46 +00:00
|
|
|
func foo(w gopher.ResponseWriter, r *gopher.Request) {
|
|
|
|
w.Write([]byte("Foo!"))
|
|
|
|
}
|
|
|
|
|
2016-09-14 03:45:49 +00:00
|
|
|
func main() {
|
2017-02-13 08:18:27 +00:00
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
|
|
|
// Standard Server
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
mux := gopher.NewServeMux()
|
|
|
|
|
|
|
|
mux.HandleFunc("/", index)
|
|
|
|
mux.HandleFunc("/foo", foo)
|
|
|
|
mux.HandleFunc("/hello", hello)
|
|
|
|
|
|
|
|
log.Fatal(gopher.ListenAndServe("localhost:70", mux))
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// TLS server
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
mux := gopher.NewServeMux()
|
|
|
|
|
|
|
|
mux.HandleFunc("/", index)
|
|
|
|
mux.HandleFunc("/foo", foo)
|
|
|
|
mux.HandleFunc("/hello", hello)
|
|
|
|
|
|
|
|
log.Fatal(
|
|
|
|
gopher.ListenAndServeTLS(
|
|
|
|
"localhost:73", "cert.pem", "key.pem", mux,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
wg.Done()
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Wait()
|
2016-09-14 03:45:49 +00:00
|
|
|
}
|