Documentation
¶
Overview ¶
Package gemini implements the protocol for use with a file server, certificate generation and facilities for interceptors and middlewares.
Index ¶
- Constants
- Variables
- func Error(code int, err error) error
- func GenX509KeyPair(host string, daysvalid int) (tls.Certificate, error)
- func TLSConfig(sni string, cert tls.Certificate) *tls.Config
- type GmiError
- type Handler
- type HandlerFunc
- type Interceptor
- func (m *Interceptor) Flush()
- func (m *Interceptor) FlushBody()
- func (m *Interceptor) FlushHeader()
- func (m *Interceptor) HasBody() bool
- func (m *Interceptor) HasHeader() bool
- func (m *Interceptor) Write(body []byte) (int, error)
- func (m *Interceptor) WriteHeader(code int, message string) (int, error)
- type Middleware
- type Mux
- type Request
- type ResponseWriter
- type Server
Constants ¶
const ( StatusInput = 10 StatusSensitiveInput = 11 StatusSuccess = 20 StatusRedirectTemporary = 30 StatusRedirectPermanent = 31 StatusTemporaryFailure = 40 StatusCgiError = 42 StatusProxyError = 43 StatusSlowDown = 44 StatusPermanentFailure = 50 StatusNotFound = 51 StatusGone = 52 StatusProxyRequestRefused = 53 StatusBadRequest = 59 StatusClientCertificateRequired = 60 StatusCertificateNotAuthorized = 61 StatusCertificateNotValid = 62 )
const ( Termination = "\r\n" URLMaxBytes = 1024 IndexFile = "index.gmi" MimeType = "text/gemini; charset=utf-8" MimeTypeCS = "text/gemini; charset=utf-8; lang=cs" )
Variables ¶
var ( ErrServerClosed = errors.New("gemini: server closed") ErrHeaderTooLong = errors.New("gemini: header too long") ErrMissingFile = errors.New("gemini: no such file") ErrEmptyRequest = errors.New("gemini: empty request") ErrEmptyRequestURL = errors.New("gemini: empty request URL") ErrInvalidPath = errors.New("gemini: path error") ErrInvalidHost = errors.New("gemini: empty host") ErrInvalidUtf8 = errors.New("gemini: empty request URL") ErrUnknownProtocol = fmt.Errorf("gemini: unknown protocol scheme") )
Functions ¶
func GenX509KeyPair ¶
func GenX509KeyPair(host string, daysvalid int) (tls.Certificate, error)
GenX509KeyPair generates a TLS keypair with one week validity.
Types ¶
type Handler ¶
type Handler interface {
ServeGemini(ResponseWriter, *Request)
}
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
The HandlerFunc type is an adapter to allow the use of ordinary functions as Gemini handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (HandlerFunc) ServeGemini ¶
func (f HandlerFunc) ServeGemini(w ResponseWriter, r *Request)
ServeGemini calls f(w, r).
type Interceptor ¶
type Interceptor struct { // Interceptor is the underlying io.Writer that buffers the response body Body bytes.Buffer // Code is the status code. Code int // Meta is the header addition, such as the mimetype. Meta string // contains filtered or unexported fields }
Interceptor is a ResponseWriter wrapper that may be used as buffer.
A middleware may pass it to the next handlers ServeGemini method as a drop in replacement for the response writer. See the logger and cache middlewares for examples.
Note that the body being written two times and the complete caching of the body in the memory.
func NewInterceptor ¶
func NewInterceptor(responseWriter ResponseWriter) (m *Interceptor)
NewInterceptor creates a new Interceptor by wrapping the given response writer.
func (*Interceptor) Flush ¶
func (m *Interceptor) Flush()
FlushAll flushes headers, status code and body to the underlying ResponseWriter.
func (*Interceptor) FlushBody ¶
func (m *Interceptor) FlushBody()
FlushBody flushes to the underlying responsewriter.
func (*Interceptor) FlushHeader ¶
func (m *Interceptor) FlushHeader()
FlushHeader writes the header to the underlying ResponseWriter.
func (*Interceptor) HasBody ¶
func (m *Interceptor) HasBody() bool
func (*Interceptor) HasHeader ¶
func (m *Interceptor) HasHeader() bool
func (*Interceptor) Write ¶
func (m *Interceptor) Write(body []byte) (int, error)
Write writes to the underlying buffer and tracks this call as change
func (*Interceptor) WriteHeader ¶
func (m *Interceptor) WriteHeader(code int, message string) (int, error)
WriteHeader writes the cached status code and tracks this call as change
type Middleware ¶
Middlewares type is a slice of gemini middleware handlers.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
func (*Mux) ServeGemini ¶
func (m *Mux) ServeGemini(w ResponseWriter, r *Request)
func (*Mux) Use ¶
func (m *Mux) Use(handlers ...Middleware)
Use appends a handler to the Mux handler stack.
type ResponseWriter ¶
type Server ¶
type Server struct { // Addr is the address the server is listening on. Addr string // Hostname or common name of the server. This is used for absolute redirects. Hostname string // Logger enables logging of the gemini server for debugging purposes. Logger *log.Logger TLSConfig *tls.Config TLSConfigLoader func() (*tls.Config, error) Handler Handler // handler to invoke ReadTimeout time.Duration MaxOpenConns int // contains filtered or unexported fields }