mercury

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 15 Imported by: 0

README

Mercury

A framework for writing Go applications using the Gemini protocol


For more information about Gemini, see https://gemini.circumlunar.space/ or gemini://gemini.circumlunar.space

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorHandler

func DefaultErrorHandler(ctx *Ctx, err error) error

func FingerprintCertificate

func FingerprintCertificate(cert *x509.Certificate) []byte

FingerprintCertificate computes a SHA1 hash of the raw certificate bytes.

func FingerprintCertificateWithHash

func FingerprintCertificateWithHash(cert *x509.Certificate, hashType crypto.Hash) []byte

FingerprintCertificateWithHash computes a hash of a given type from the raw certificate bytes.

func NewError

func NewError(message string, status Status) error

Types

type App

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

func New

func New(conf ...AppConfigFunction) (*App, error)

func (*App) Add

func (app *App) Add(path string, handlerFunction HandlerFunction)

Add registers a handler function to be used to serve requests to a specific URL.

func (*App) Listen

func (app *App) Listen(addr string) error

func (*App) Shutdown

func (app *App) Shutdown() error

Shutdown shuts down the app if it's listening

func (*App) Use

func (app *App) Use(hf HandlerFunction)

func (*App) UseOnPath

func (app *App) UseOnPath(path string, hf HandlerFunction)

type AppConfigFunction

type AppConfigFunction func(*App) error

func WithDebugModeEnabled

func WithDebugModeEnabled() AppConfigFunction

func WithDisableStartupMessage

func WithDisableStartupMessage() AppConfigFunction

func WithErrorHandler

func WithErrorHandler(eh ErrorHandlerFunction) AppConfigFunction

WithErrorHandler sets the error handler that's used by the app.

The error handler must not make use of request variables. The error handler must not call (*ctx).Next()

func WithLogger

func WithLogger(x *log.Logger) AppConfigFunction

WithLogger sets the error logger to the one provided.

To disable logging, use this function with a nil logger.

func WithReadTimeout

func WithReadTimeout(x time.Duration) AppConfigFunction

WithReadTimeout sets the read timeout for any incoming connections.

Setting this value to zero disables read timeouts.

func WithServerName

func WithServerName(name string) AppConfigFunction

func WithWriteTimeout

func WithWriteTimeout(x time.Duration) AppConfigFunction

WithWriteTimeout sets the write timeout for any incoming connections.

Setting this value to zero disables write timeouts.

func WithX509KeyData

func WithX509KeyData(certPEMBlock, keyPEMBlock []byte) AppConfigFunction

WithX509KeyData loads an X509 certificate and key from the provided bytes.

func WithX509KeyPair

func WithX509KeyPair(certFile, keyFile string) AppConfigFunction

WithX509KeyPair loads an X509 certificate file and key file from disk.

type Ctx

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

func (*Ctx) ClearBody

func (ctx *Ctx) ClearBody()

func (*Ctx) GetBody

func (ctx *Ctx) GetBody() *[]byte

func (*Ctx) GetClientCertificates

func (ctx *Ctx) GetClientCertificates() []*x509.Certificate

func (*Ctx) GetMeta

func (ctx *Ctx) GetMeta() *[]byte

func (*Ctx) GetRawQuery

func (ctx *Ctx) GetRawQuery() string

func (*Ctx) GetRawQueryWithDefault

func (ctx *Ctx) GetRawQueryWithDefault(defaultValue string) string

func (*Ctx) GetRemoteAddress

func (ctx *Ctx) GetRemoteAddress() net.Addr

func (*Ctx) GetRequestURL

func (ctx *Ctx) GetRequestURL() *url.URL

func (*Ctx) GetURLParam

func (ctx *Ctx) GetURLParam(name string) string

func (*Ctx) GetURLParamWithDefault

func (ctx *Ctx) GetURLParamWithDefault(name, defaultValue string) string

func (*Ctx) Next

func (ctx *Ctx) Next() error

func (*Ctx) SetBody

func (ctx *Ctx) SetBody(body string)

SetBody sets the response body to a single string. This will be overridden if (*ctx).SetBodyBuilder is used.

func (*Ctx) SetBodyBuilder

func (ctx *Ctx) SetBodyBuilder(sb *strings.Builder)

SetBodyBuilder allows a strings.Builder to be used to create the response body. This will overwrite any other calls made to set the response body.

To undo this, call SetBodyBuilder with a nil *strings.Builder then call other body-setting functions as normal.

func (*Ctx) SetBodyFromFile

func (ctx *Ctx) SetBodyFromFile(filename string) error

SetBodyFromFile reads a file with the specified name and uses its contents as the response body. This will be overridden if (*ctx).SetBodyBuilder is used.

func (*Ctx) SetMeta

func (ctx *Ctx) SetMeta(meta string) error

func (*Ctx) SetStatus

func (ctx *Ctx) SetStatus(status Status)

type Error

type Error struct {
	Message string
	Status  Status
}

func (Error) Error

func (e Error) Error() string

type ErrorHandlerFunction

type ErrorHandlerFunction func(ctx *Ctx, err error) error

type HandlerFunction

type HandlerFunction func(ctx *Ctx) error

type Status

type Status int
const (
	StatusInput          Status = 10
	StatusSensitiveInput Status = 11

	StatusSuccess Status = 20

	StatusTemporaryRedirect Status = 30
	StatusPermanentRedirect Status = 31

	StatusTemporaryFailure  Status = 40
	StatusServerUnavailable Status = 41
	StatusCGIError          Status = 42
	StatusProxyError        Status = 43
	StatusSlowDown          Status = 44

	StatusPermanentFailure    Status = 50
	StatusNotFound            Status = 51
	StatusGone                Status = 52
	StatusProxyRequestRefused Status = 53
	StatusBadRequest          Status = 59

	StatusClientCertificateRequired Status = 60
	StatusCertificateNotAuthorised  Status = 61
	StatusCertificateNotValid       Status = 62
)

Jump to

Keyboard shortcuts

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