blob: 6e7ece215a36128588366af65e960c6cc5508e66 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package main
import (
"io/ioutil"
"log"
"net/url"
"strings"
gemini "git.sr.ht/~yotam/go-gemini"
)
type ExampleHandler struct {
}
func (h ExampleHandler) Handle(r gemini.Request) gemini.Response {
u, err := url.Parse(r.URL)
if err != nil {
body := ioutil.NopCloser(strings.NewReader(err.Error()))
return gemini.Response{40, "text/gemini", body}
}
if u.Path != "/" {
body := ioutil.NopCloser(strings.NewReader("Not Found"))
return gemini.Response{50, "text/gemini", body}
}
body := ioutil.NopCloser(strings.NewReader("Hello World"))
return gemini.Response{20, "text/gemini", body}
}
func main() {
handler := ExampleHandler{}
err := gemini.ListenAndServe(":1965", "server.crt", "server.key", handler)
if err != nil {
log.Fatal(err)
}
}
|