Documentation ¶
Index ¶
- Variables
- func Error(w ResponseWriter, message string, status StatusCode)
- func Input(w ResponseWriter, prompt string, sensitive bool)
- func Redirect(w ResponseWriter, location string, permanent bool)
- func RedirectURL(w ResponseWriter, location url.URL, permanent bool)
- func RequireCert(w ResponseWriter, r *Request, message ...string) bool
- func SlowDown(w ResponseWriter)
- func VerifyCert(w ResponseWriter, r *Request, ...) bool
- type Flusher
- type GeminiServer
- type Handler
- type HandlerFunc
- type Header
- type Method
- type Request
- type ResponseWriter
- type StatusCode
- type Unwrapper
Constants ¶
This section is empty.
Variables ¶
var BodyNotAllowed error = errors.New("Body Not allowed for non 2X status codes")
The error that is returned when a call to Write was made when the status code is not 2X
Functions ¶
func Error ¶
func Error(w ResponseWriter, message string, status StatusCode)
Send a response to the client with a given message
func Input ¶
func Input(w ResponseWriter, prompt string, sensitive bool)
Request input from the client
func Redirect ¶
func Redirect(w ResponseWriter, location string, permanent bool)
Redirect the client to a new location
func RedirectURL ¶
func RedirectURL(w ResponseWriter, location url.URL, permanent bool)
Redirect the client to a new location using a url object
func RequireCert ¶
func RequireCert(w ResponseWriter, r *Request, message ...string) bool
Require a certificate to be provided by the client
If no certificate is provided, then a CertRequired response is sent with the optional message and true is returned
If a certificate is provided, then no action is taken and false is returned ¶
Returns true when a response was sent to the client
func VerifyCert ¶
func VerifyCert(w ResponseWriter, r *Request, verify func(chain []*x509.Certificate) (verified bool, err string), message ...string) bool
Require a certificate to be provided by the client and verify the certificate with the provided function
If no certificate is sent, then a CertRequired response is sent with the optional message and true is returned
Verify is called with the certificate chain. If the certificate is verified, then true is returned. If the certificate is unauthorized, then false is returned with an optional error message.
Returns true when a response was sent to the client
Types ¶
type Flusher ¶
type Flusher interface { // Send any pending data to the client Flush() error }
ResponseWriters which are Flushers have an internal buffer which can be sent to the client with the Flush method.
type GeminiServer ¶
type GeminiServer struct { HandshakeTimeout time.Duration Config *tls.Config // contains filtered or unexported fields }
func NewGeminiServer ¶
func NewGeminiServer(tlsConfig *tls.Config) *GeminiServer
Create a new Gemini server using the provided tls config
Because the Gemini protocol supports client certificates, the default setting for tlsConfig.ClientAuth is set to RequestClientCert.
func (*GeminiServer) Handler ¶
func (self *GeminiServer) Handler(handler Handler)
Set the handler for the server
func (*GeminiServer) HandlerFunc ¶
func (self *GeminiServer) HandlerFunc(handler func(ResponseWriter, *Request))
Set the handler for the server
func (*GeminiServer) ListenAndServe ¶
func (self *GeminiServer) ListenAndServe(addr string) error
Start listening and server the Gemini server.
if addr is empty, then the default port 1965 will be used.
If the host in the addr parameter is empty or a literal unspecified IP addr, ListenAndServe listens on all available unicast and anycast IP addresses of the local system. To only use IPv4, use network "tcp4". The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty as in "127.0.0.1:" or "", then the default port 1965 is used. If the port is instead "0", as in ":0" or "\[::1]:0", a port number is automatically chosen. The \[Addr] method of \[Listener] can be used to discover the chosen port.
type Handler ¶
type Handler interface { // Serve a gemini response for a given request ServeGemini(ResponseWriter, *Request) }
Gemini Handler can process a gemini request by defining the ServeGemini method.
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
A gemini handler as a function
func (HandlerFunc) ServeGemini ¶
func (self HandlerFunc) ServeGemini(w ResponseWriter, r *Request)
type Header ¶
type Header string
func (*Header) MimeType ¶
Set the mimetype of the response
Optional languages can be added to the mimetype. These languages must be IETF language tags.
This should be used with the 2X OK response
type Request ¶
type Request struct { // The Url of the request URL *url.URL // The scheme of the request (titan or gemini) Method Method // The query of the request with any urlencodings decoded Query string // The host of the request Host string // The path of the request with any urlencodings decoded Path string // ip address of the client RemoteAddr string // The original uri of the request RequestURI string // The size of the body (if method is titan) Size int64 // The content type of the body (if method is titan) ContentType string // The token for the titan request Token string // The body of the titan request Body io.Reader // Any provided client certificates ClientCerts []*x509.Certificate // The tls state TLS tls.ConnectionState }
type ResponseWriter ¶
type ResponseWriter interface { // Get a reference to the header Header() *Header // Write to the client // // It is an error to call this method if a status other than 2X was sent // // If WriteHeader was not already called, then WriteHeader(20) will be called // for you. Write([]byte) (int, error) // Send the header to the client // // If the status 20 is sent and no header was provided, then the mimetype // text/gemini will be set by default. WriteHeader(status StatusCode) error }
Response object for gemini requests.
All ResponseWriters provide a header and writer.
Most ResponseWriters also are Flusher
type StatusCode ¶
type StatusCode int
const ( StatusInput StatusCode = 10 StatusSensitiveInput StatusCode = 11 StatusSuccess StatusCode = 20 StatusRedirect StatusCode = 30 StatusRedirectPerm StatusCode = 31 StatusTempFail StatusCode = 40 StatusCGIError StatusCode = 42 StatusProxyError StatusCode = 43 StatusSlowDown StatusCode = 44 StatusPermFail StatusCode = 50 StatusNotFound StatusCode = 51 StatusGone StatusCode = 52 StatusProxyRefused StatusCode = 53 StatusBadRequest StatusCode = 59 StatusCertRequired StatusCode = 60 StatusCertNotValid StatusCode = 62 )