gemini

package module
v0.0.0-...-e1cd905 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 11 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Gemini

Golang server library for Gemini protocol based on standart net/http library.

Usage

import "github.com/nxshock/gemini"

gemini.HandleFunc("/", func(w gemini.ResponseWriter, r *gemini.Request) {
	w.Write([]byte("hello"))
})

err := gemini.ListenAndServeTLS("", "localhost.crt", "localhost.key", nil)
if err != nil {
	panic(err)
}

Documentation

Index

Constants

View Source
const (
	StatusInput          = 10 // As per definition of single-digit code 1 in 3.2.
	StatusSensitiveInput = 11 // As per status code 10, but for use with sensitive input such as passwords. Clients should present the prompt as per status code 10, but the user's input should not be echoed to the screen to prevent it being read by "shoulder surfers".

	// The request was handled successfully and a response body will follow the response header.
	StatusSuccess = 20

	// The server is redirecting the client to a new location for the requested resource.
	StatusRedirectTemporary = 30

	StatusRedirectPermanent = 31 // The requested resource should be consistently requested from the new URL provided in future. Tools like search engine indexers or content aggregators should update their configurations to avoid requesting the old URL, and end-user clients may automatically update bookmarks, etc. Note that clients which only pay attention to the initial digit of status codes will treat this as a temporary redirect. They will still end up at the right place, they just won't be able to make use of the knowledge that this redirect is permanent, so they'll pay a small performance penalty by having to follow the redirect each time.
	StatusTemporaryFailure  = 40 // As per definition of single-digit code 4 in 3.2.
	StatusServerUnavailable = 41 // The server is unavailable due to overload or maintenance. (cf HTTP 503)
	StatusCgiError          = 42 // A CGI process, or similar system for generating dynamic content, died unexpectedly or timed out.
	StatusProxyError        = 43 // A proxy request failed because the server was unable to successfully complete a transaction with the remote host. (cf HTTP 502, 504)
	StatusSlowDown          = 44 // Rate limiting is in effect. <META> is an integer number of seconds which the client must wait before another request is made to this server. (cf HTTP 429)

	// The request has failed.
	StatusPermanentFailure = 50

	StatusNotFound            = 51 // The requested resource could not be found but may be available in the future. (cf HTTP 404) (struggling to remember this important status code? Easy: you can't find things hidden at Area 51!)
	StatusGone                = 52 // The resource requested is no longer available and will not be available again. Search engines and similar tools should remove this resource from their indices. Content aggregators should stop requesting the resource and convey to their human users that the subscribed resource is gone. (cf HTTP 410)
	StatusProxyRequestRefused = 53 // The request was for a resource at a domain not served by the server and the server does not accept proxy requests.
	StatusBadRequest          = 59 // The server was unable to parse the client's request, presumably due to a malformed request. (cf HTTP 400)

	// The requested resource requires a client certificate to access.
	StatusClientCertificateRequired = 60

	StatusCertificateNotAuthorised = 61 // The supplied client certificate is not authorised for accessing the particular requested resource. The problem is not with the certificate itself, which may be authorised for other resources.
	StatusCertificateNotValid      = 62 // The supplied client certificate was not accepted because it is not valid. This indicates a problem with the certificate in and of itself, with no consideration of the particular requested resource. The most likely cause is that the certificate's validity start date is in the future or its expiry date has passed, but this code may also indicate an invalid signature, or a violation of a X509 standard requirements. The <META> should provide more information about the exact error.)
)

Variables

View Source
var DefaultServeMux = &defaultServeMux

DefaultServeMux is the default ServeMux used by Serve.

Functions

func Error

func Error(w ResponseWriter, error string, code uint8)

Error replies to the request with the specified error message and Gemini code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.

func Handle

func Handle(pattern string, handler Handler)

Handle registers the handler for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.

func HandleFunc

func HandleFunc(pattern string, handler func(ResponseWriter, *Request))

HandleFunc registers the handler function for the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patterns are matched.

func ListenAndServeTLS

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error

ListenAndServeTLS acts identically to ListenAndServe, except that it expects HTTPS connections. Additionally, files containing a certificate and matching private key for the server must be provided. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.

func NotFound

func NotFound(w ResponseWriter, r *Request)

func Redirect

func Redirect(w ResponseWriter, r *Request, url string, code uint8)

Redirect replies to the request with a redirect to url, which may be a path relative to the request path.

The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther.

If the Content-Type header has not been set, Redirect sets it to "text/html; charset=utf-8" and writes a small HTML body. Setting the Content-Type header to any value, including nil, disables that behavior.

Types

type Handler

type Handler interface {
	ServeGemini(ResponseWriter, *Request)
}

func NotFoundHandler

func NotFoundHandler() Handler

NotFoundHandler returns a simple request handler that replies to each request with a “404 page not found” reply.

func RedirectHandler

func RedirectHandler(url string, code uint8) Handler

RedirectHandler returns a request handler that redirects each request it receives to the given url using the given status code.

The provided code should be in the 3xx range and is usually StatusMovedPermanently, StatusFound or StatusSeeOther.

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

func (HandlerFunc) ServeGemini

func (f HandlerFunc) ServeGemini(w ResponseWriter, r *Request)
type Header struct {
	Status uint8
	Meta   string
}

func (*Header) Bytes

func (responseHeader *Header) Bytes() []byte

type Request

type Request struct {
	URL        *url.URL
	Host       string
	RequestURI string
	RemoteAddr string
	Query      string
}

type ResponseWriter

type ResponseWriter interface {
	Header() *Header
	Write([]byte) (int, error)
	WriteHeader(statusCode uint8, meta string)
}

type ServeMux

type ServeMux struct {
	// contains filtered or unexported fields
}

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler Handler)

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request))

func (*ServeMux) Handler

func (mux *ServeMux) Handler(r *Request) (h Handler, pattern string)

func (*ServeMux) ServeGemini

func (mux *ServeMux) ServeGemini(w ResponseWriter, r *Request)

type Server

type Server struct {
	Addr    string
	Handler Handler

	ListenerAcceptErrorHandler func(error)
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) ListenAndServeTLS

func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error

func (*Server) Stop

func (server *Server) Stop() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址