server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 10 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, 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) 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

Jump to

Keyboard shortcuts

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