server

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package server provides utilities for creating a functioning and useful Gemini server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler func(request Request)

A Handler is a function to handle a Request by calling its various methods. The function is called when a request that it can handle is made, as outlined in Server.RegisterHandler

type Request

type Request struct {
	// URI contains a [url.URL] object corresponding to the URL of the request.
	URI url.URL
	// Params contains a map of URL params passed into the request. Nil if there are no params.
	Params map[string]string
	// contains filtered or unexported fields
}

Request wraps a Gemini request.

func (*Request) Error

func (r *Request) Error(code int, message string) error

Error responds with an error code and message After calling this method, the Request has been terminated.

func (*Request) Gemtext

func (r *Request) Gemtext(source string) error

Gemtext responds using a gemtext string and status code 20. After calling this method, the Request has been terminated.

func (*Request) GemtextFile

func (r *Request) GemtextFile(path string) error

GemtextFile responds using gemtext from a file and status code 20. After calling this method, the Request has been terminated.

func (*Request) GetClientCertificates

func (r *Request) GetClientCertificates() []*x509.Certificate

GetClientCertificates retrieves the client certificate(s) for the Request

type Server

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

A Server contains information required to run a TCP/TLS service capable of serving Gemini content over the internet

func New

func New() *Server

New creates a new Server

func (*Server) Close added in v0.4.0

func (s *Server) Close() error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string, tlsConfig *tls.Config) error

ListenAndServe starts the Server running on a specific port using the provided TLS configuration

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(path string, handler Handler)

RegisterHandler sets up a Handler to handle any Request that comes to a path

func (*Server) RegisterTitanHandler added in v0.4.0

func (s *Server) RegisterTitanHandler(path string, handler TitanHandler)

RegisterTitanHandler sets up a TitanHandler to handle any TitanRequest that comes to a path

type TitanHandler added in v0.4.0

type TitanHandler func(request TitanRequest)

A TitanHandler is a function to handle a TitanRequest by calling its various methods. The function is called when a titan request that it can handle is made as outlined in Server.RegisterTitanHandler

type TitanRequest added in v0.4.0

type TitanRequest struct {
	Request
	// Token contains the answer to the security question, or an empty string
	Token string
	// MIMEType contains the MIME type of the data. Defaults to "text/gemini"
	MIMEType string
	// Body contains the data sent by the client
	Body []byte
}

TitanRequest wraps a Titan request.

Contains Request, so can be used like a Gemini request as well.

Jump to

Keyboard shortcuts

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