1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-04-27 16:55:09 +02:00
go-gemini/doc.go

56 lines
1.4 KiB
Go
Raw Normal View History

2021-01-10 07:16:50 +01:00
/*
2021-02-18 06:37:56 +01:00
Package gemini provides Gemini client and server implementations.
2021-01-10 07:16:50 +01:00
Client is a Gemini client.
client := &gemini.Client{}
2021-02-23 20:29:37 +01:00
ctx := context.Background()
resp, err := client.Get(ctx, "gemini://example.com")
2021-01-10 07:16:50 +01:00
if err != nil {
// handle error
}
defer resp.Body.Close()
2021-01-10 07:16:50 +01:00
// ...
Server is a Gemini server.
server := &gemini.Server{
2021-01-10 07:21:56 +01:00
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
2021-01-10 07:16:50 +01:00
}
Servers should be configured with certificates:
2021-02-21 06:56:37 +01:00
certificates := &certificate.Store{}
2021-02-23 20:29:37 +01:00
certificates.Register("localhost")
2021-02-21 06:56:37 +01:00
err := certificates.Load("/var/lib/gemini/certs")
2021-01-10 07:16:50 +01:00
if err != nil {
// handle error
}
2021-02-23 20:29:37 +01:00
server.GetCertificate = certificates.Get
2021-01-10 07:16:50 +01:00
2021-03-15 20:44:35 +01:00
Mux is a Gemini request multiplexer.
2022-02-16 18:01:55 +01:00
Mux can handle requests for multiple hosts and paths.
2021-01-10 07:16:50 +01:00
2021-03-15 20:44:35 +01:00
mux := &gemini.Mux{}
2021-02-21 06:56:37 +01:00
mux.HandleFunc("example.com", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
2021-01-10 07:16:50 +01:00
fmt.Fprint(w, "Welcome to example.com")
})
2021-02-21 06:56:37 +01:00
mux.HandleFunc("example.org/about.gmi", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
2021-02-18 06:37:56 +01:00
fmt.Fprint(w, "About example.org")
2021-01-10 07:16:50 +01:00
})
2022-02-16 18:01:55 +01:00
mux.HandleFunc("/images/", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
w.WriteHeader(gemini.StatusGone, "Gone forever")
2021-01-10 07:16:50 +01:00
})
2021-02-18 06:37:56 +01:00
server.Handler = mux
2021-01-10 07:16:50 +01:00
To start the server, call ListenAndServe:
2021-02-23 20:29:37 +01:00
ctx := context.Background()
err := server.ListenAndServe(ctx)
2021-01-10 07:16:50 +01:00
if err != nil {
// handle error
}
*/
package gemini