speedy

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

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

Go to latest
Published: Jan 7, 2024 License: MIT Imports: 5 Imported by: 0

README

Speedy

Go based wrapping package on-top of standard HTTP/HTTP2 implementations.

Documentation

Overview

Speedy aims to be a Go wrapper around standard net.HTTP implementations to provide seamless integration and helpful utilities.

It is NOT a total framework, and instead is a lightweight adapter on existing tooling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapHandler

func WrapHandler(handler Handler) http.HandlerFunc

WrapHandler takes a speedy.Handler and converts it for use with http.HandlerFunc.

Types

type Conn

type Conn struct {
}

Conn is used to provide a combined handler experience simplifying the process of handling connections

func NewConn

func NewConn(w http.ResponseWriter, r *http.Request) *Conn

NewConn wraps a standard http.HandlerFunc parameters into a new connection.

type Handler

type Handler func(conn *Conn) error

Handler is the type of function that can respond to a HTTP request. It is provided a combined struct of Conn which contains the request and response objects.

type Muxer

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

Muxer is an extension on the http.ServeMux that handles routes. The final http.ServeMux can be built during runtime.

func NewMuxer

func NewMuxer() *Muxer

func (*Muxer) Add

func (m *Muxer) Add(path string, handlers ...Handler) *Route

func (Muxer) BuildServeMux

func (m Muxer) BuildServeMux() *http.ServeMux

func (*Muxer) Delete

func (m *Muxer) Delete(pattern string, handler Handler)

Delete binds an endpoint handler for a pattern path limited to a DELETE method.

func (*Muxer) Get

func (m *Muxer) Get(path string, handler Handler)

Get binds an endpoint handler for a pattern path limited to a GET method.

func (*Muxer) Handle

func (m *Muxer) Handle(path string, handler Handler)

Handle binds an endpoint handler for a pattern path with no method limitations.

Note that this will be called last in the event that another method specific request is present as that handler is considered "more specific".

func (*Muxer) Post

func (m *Muxer) Post(pattern string, handler Handler)

Post binds an endpoint handler for a pattern path limited to a POST method.

func (*Muxer) Put

func (m *Muxer) Put(pattern string, handler Handler)

Put binds an endpoint handler for a pattern path limited to a PUT method.

func (*Muxer) Use

func (m *Muxer) Use(handler Handler)

Use binds middleware to the root Server handler for use on all requests. These are applied in order of usage.

type Route

type Route struct {
	Method string
	Path   string

	MiddlewareBefore []Handler
	MiddlewareAfter  []Handler

	Parent   *Route
	Children []*Route
	Handler  Handler
}

func (Route) AbsPath

func (r Route) AbsPath() string

func (*Route) AddChild

func (r *Route) AddChild(path string, handlers ...Handler) *Route

func (*Route) AddMethod

func (r *Route) AddMethod(method string, handler Handler) *Route

func (*Route) AddMiddleware

func (r *Route) AddMiddleware(handler Handler) *Route

func (*Route) AddMiddlewareAfter

func (r *Route) AddMiddlewareAfter(handler Handler) *Route

func (*Route) Delete

func (r *Route) Delete(handler Handler) *Route

func (*Route) Get

func (r *Route) Get(handler Handler) *Route

func (*Route) Post

func (r *Route) Post(handler Handler) *Route

func (*Route) Put

func (r *Route) Put(handler Handler) *Route

func (*Route) SetHandler

func (r *Route) SetHandler(handler Handler) *Route

func (*Route) SetMethod

func (r *Route) SetMethod(method string) *Route

func (*Route) SetPath

func (r *Route) SetPath(path string) *Route

type Server

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

Server holds the main data for starting up a web HTTP server.

func NewServer

func NewServer(host string, port uint) *Server

NewServer constructs a new Server pointer for use and sets the host and port parameters.

func (Server) Address

func (s Server) Address() string

Address returns the joined host:port address

func (*Server) BuildMux

func (s *Server) BuildMux()

BuildMux assembles the final runtime http.ServeMux that will handle the requests setup for binding. This is called automatically by the [ListenAndServe] method, but is provided in case you need to rebuild it.

func (*Server) HTTP2Server

func (s *Server) HTTP2Server() *http2.Server

HTTP2Server returns the underlying http2.Server pointer. This object is only used in HTTP2 clear-text mode and not during TLS operation.

func (*Server) HTTPServer

func (s *Server) HTTPServer() *http.Server

HTTPServer returns the underlying http.Server pointer.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe opens and starts listening on the server address for incoming requests. If there is a TLS certificate and key filepath set, it will use TLS. Otherwise it will use basic HTTP.

func (*Server) ServeMux

func (s *Server) ServeMux() *http.ServeMux

ServeMux returns the underlying http.ServeMux pointer.

func (*Server) UseTLS

func (s *Server) UseTLS(certPath, keyPath string) error

UseTLS applies the certificate and key filepaths to the server to allow for SSL/TLS on the server. It performs a quick os.Stat check to ensure validity here so that you don't have to wait for the actual listen to fail.

Jump to

Keyboard shortcuts

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