-
Notifications
You must be signed in to change notification settings - Fork 6
/
README.txt
118 lines (89 loc) · 3.22 KB
/
README.txt
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package gemini // import "github.com/jackdoe/net-gemini"
gemini server implementation, check out gemini://gemini.circumlunar.space/
inspired by https://tildegit.org/solderpunk/molly-brown
Example:
package main
import (
"log"
gemini "github.com/jackdoe/net-gemini"
)
func main() {
gemini.HandleFunc("/example", func(w *gemini.Response, r *gemini.Request) {
if len(r.URL.RawQuery) == 0 {
w.SetStatus(gemini.StatusInput, "what is the answer to the ultimate question")
} else {
w.SetStatus(gemini.StatusSuccess, "text/gemini")
answer := r.URL.RawQuery
w.Write([]byte("HELLO: " + r.URL.Path + ", yes the answer is: " + answer))
}
})
gemini.Handle("/", gemini.FileServer(*root))
log.Fatal(gemini.ListenAndServeTLS("localhost:1965", "localhost.crt", "localhost.key"))
}
You can also checkout cmd/main.go as an example.
Make sure to generate your cert for localhost:
openssl req \
-x509 \
-out localhost.crt \
-keyout localhost.key \
-newkey rsa:2048 \
-nodes \
-sha256 \
-subj '/CN=localhost' \
-extensions EXT \
-config <( printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
CONSTANTS
const (
StatusInput = 10
StatusSuccess = 20
StatusSuccessEndClientCertificateSession = 21
StatusRedirectTemporary = 30
StatusRedirectPermanent = 31
StatusTemporaryFailure = 40
StatusServerUnavailable = 41
StatusCGIError = 42
StatusProxyError = 43
StatusSlowDown = 44
StatusPermanentFailure = 50
StatusNotFound = 51
StatusGone = 52
StatusProxyRequestRefused = 53
StatusBadRequest = 59
StatusClientCertRequired = 60
StatusTransientCertRequested = 61
StatusAuthorisedCertRequired = 62
StatusCertNotAccepted = 63
StatusFutureCertRejected = 64
StatusExpiredCertRejected = 65
)
FUNCTIONS
func Handle(p string, h Handler)
func HandleFunc(p string, f HandlerFunc)
func ListenAndServeTLS(addr string, certFile, keyFile string) error
func ServeFilePath(p string, w *Response, r *Request)
TYPES
type Handler interface {
ServeGemini(*Response, *Request)
}
func FileServer(root string) Handler
type HandlerFunc func(*Response, *Request)
func (f HandlerFunc) ServeGemini(w *Response, r *Request)
type Request struct {
URL *url.URL
}
type Response struct {
// Has unexported fields.
}
func (r *Response) SetStatus(s Status, mime string) error
func (r *Response) Write(b []byte) (int, error)
type Server struct {
Addr string
Handler Handler
ReadTimeout time.Duration
WriteTimeout time.Duration
Log io.Writer
// Has unexported fields.
}
func (s *Server) Close()
func (s *Server) ListenAndServeTLS(certFile, keyFile string) error
type Status int