Documentation ¶
Overview ¶
Package dioscuri implements a Gemini client, a Gemini server, and a parser for the "text/gemini" mime type.
Gemini: https://gemini.circumlunar.space/
Example (Get) ¶
rsp, err := Get(context.Background(), "gemini://gus.guru") if err != nil { log.Fatal(err) } defer rsp.Body.Close() if StatusClass(rsp.Status) != Success { log.Fatalf("bad status %d", rsp.Status) } // do something with rsp.Body _ = rsp.Body
Output:
Example (Parser) ¶
var r io.Reader // response body with mime type "text/gemini; charset=utf-8" p := NewParser(r) for { line, err := p.Next() if err == io.EOF { break // done } if err != nil { log.Fatal(err) } // do something with line _ = line }
Output:
Example (Serve) ¶
HandleFunc("/", func(w ResponseWriter, _ *Request) { w.Write([]byte("hello, gemini!")) }) err := ListenAndServe(":1965", "cert.pem", "key.rsa", nil) if err != nil { log.Fatal(err) }
Output:
Index ¶
- Constants
- Variables
- func Error(w ResponseWriter, message string, status int)
- func Handle(pattern string, h Handler)
- func HandleFunc(pattern string, h func(ResponseWriter, *Request))
- func IsGemtext(meta string) bool
- func ListenAndServe(addr string, certFile, keyFile string, h Handler) error
- func Serve(lis net.Listener, h Handler) error
- type Class
- type Handler
- type HandlerFunc
- type HeadingLine
- type Line
- type LinkLine
- type Parser
- type PreTextLine
- type PreToggleLine
- type QuoteLine
- type Request
- type Response
- type ResponseWriter
- type ServeMux
- type Server
- type TextLine
- type UnorderedListItemLine
Examples ¶
Constants ¶
const ( StatusInput = 10 StatusSensitiveInput = 11 StatusSuccess = 20 StatusTemporaryRedirect = 30 StatusPermanentRedirect = 31 StatusTemporaryFailure = 40 StatusCGIError = 42 StatusProxyError = 43 StatusSlowDown = 44 StatusPermanentFailure = 50 StatusNotFound = 51 StatusGone = 52 StatusProxyRequestRefused = 53 StatusBadRequest = 59 StatusClientCertificateRequired = 60 StatusCertificateNotAuthorised = 61 StatusCertificateNotValid = 62 )
Specific status codes.
const (
DefaultMimeType = "text/gemini; charset=utf-8"
)
Variables ¶
var DefaultServeMux = &ServeMux{}
Functions ¶
func Error ¶
func Error(w ResponseWriter, message string, status int)
Error replies to the request with the specified message in the meta portion of the response and the given status code.
func HandleFunc ¶
func HandleFunc(pattern string, h func(ResponseWriter, *Request))
Types ¶
type Class ¶
type Class int
const ( Input Class Success Redirect TemporaryFailure PermanentFailure ClientCertificateRequired )
func StatusClass ¶
type Handler ¶
type Handler interface {
ServeGemini(ResponseWriter, *Request)
}
func FileServer ¶
func NotFoundHandler ¶
func NotFoundHandler() Handler
func RedirectHandler ¶
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
func (HandlerFunc) ServeGemini ¶
func (h HandlerFunc) ServeGemini(w ResponseWriter, r *Request)
type HeadingLine ¶
func (HeadingLine) String ¶
func (l HeadingLine) String() string
type Line ¶
type Line interface { String() string // contains filtered or unexported methods }
A Line represents a line of gemtext (i.e., "text/gemini" mime type) content.
func ParseGemtextLine ¶
ParseGemtextLine parses the "text/gemini" content line specified by the given bytes. The pre parameter indicates whether preformatted mode is currently on or off. The function returns the parsed line, the updated value for the preformatted mode (which should be passed in as the argument when parsing the next line), and any error.
ParseGemtextLine assumes the input is UTF-8 encoded.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses "text/gemini" input, otherwise referred to as gemtext. It assumes the input is UTF-8 encoded. Use NewParser to constrct a Parser. See package-level example for usage.
type PreTextLine ¶
type PreTextLine []byte
func (PreTextLine) String ¶
func (l PreTextLine) String() string
type PreToggleLine ¶
type PreToggleLine struct { On bool // whether the line toggles preformatting mode on or off AltText []byte // valid if On == true }
func (PreToggleLine) String ¶
func (l PreToggleLine) String() string
type Request ¶
type Request struct { URL *url.URL Certificates []tls.Certificate }
A Request represents a Gemini protocol request.
func NewRequest ¶
NewRequest constructs a Gemini request for the given URL.
type Response ¶
type Response struct { Status int RawMeta []byte Body io.ReadCloser }
Response represents a Gemini protocol response.
type ResponseWriter ¶
type ResponseWriter interface { // WriteHeader writes the status code and meta portion of the response header. WriteHeader(status int, meta string) // Write writes the data to the connection as part of the response body. // If WriteHeader has not yet been called, Write calls WriteHeader with // status code 20 and and meta "text/gemini; charset=utf-8". Write(p []byte) (n int, err error) }
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
func (*ServeMux) HandleFunc ¶
func (mux *ServeMux) HandleFunc(pattern string, h func(ResponseWriter, *Request))
func (*ServeMux) ServeGemini ¶
func (mux *ServeMux) ServeGemini(w ResponseWriter, r *Request)
type Server ¶
type Server struct { // Address specifies the TCP address to listen on. // If empty, ":1965" is used. Addr string // Handler to invoke. // If nil, DefaultServeMux is used. Handler Handler ReadTimeout time.Duration WriteTimeout time.Duration }
func (*Server) ListenAndServe ¶
type UnorderedListItemLine ¶
type UnorderedListItemLine []byte
func (UnorderedListItemLine) String ¶
func (l UnorderedListItemLine) String() string