tea

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: GPL-3.0 Imports: 19 Imported by: 16

README

go-tea

Golang entrypoint for REST web apps and client libraries (internal only).

Installation

go-tea may be installed using the go get command:

go get github.com/pghq/go-tea

Usage

To create a new router:

import "github.com/pghq/go-tea"

r := tea.NewRouter("")
r.Route("GET", "/test", func(w http.ResponseWriter, r *http.Request){})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go added in v0.3.0

func Go[Q any, R any](h RouteHandler, method, endpoint string, fn func(context.Context, Q) (R, error), middlewares ...Middleware)

Go handle a http request

func MethodNotAllowedHandler

func MethodNotAllowedHandler(w http.ResponseWriter, _ *http.Request)

MethodNotAllowedHandler is a custom handler for method not allowed requests

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, _ *http.Request)

NotFoundHandler is a custom handler for not found requests

func Parse added in v0.0.38

func Parse(w http.ResponseWriter, r *http.Request, v interface{}) error

Parse is a method to decode a http request into a value schema struct tags are supported

func ParseHeaders added in v0.2.7

func ParseHeaders(r *http.Request, v interface{})

ParseHeaders decode http request headers

func ParsePath added in v0.2.7

func ParsePath(r *http.Request, v interface{}) error

ParsePath decode http path

func ParseQuery added in v0.2.7

func ParseQuery(r *http.Request, v interface{}) error

ParseQuery decode http query

func Send added in v0.0.38

func Send(w http.ResponseWriter, r *http.Request, raw interface{})

Send sends an HTTP response based on content type and body

Types

type CORSMiddleware

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

CORSMiddleware is an implementation of the CORS middleware providing method, origin, and credential allowance

func NewCORSMiddleware

func NewCORSMiddleware() CORSMiddleware

NewCORSMiddleware constructs a new middleware that handles CORS

func (CORSMiddleware) Handle

func (m CORSMiddleware) Handle(next http.Handler) http.Handler

Handle provides an http handler for handling CORS

type Middleware

type Middleware interface {
	Handle(http.Handler) http.Handler
}

Middleware represents a handler that is called to for example, modify request/response before or after the principal handler is called. Each Middleware is responsible for calling the next middleware in the chain (or not if continued execution is not desired)

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc handles http middleware requests

func (MiddlewareFunc) Handle

func (m MiddlewareFunc) Handle(h http.Handler) http.Handler

Handle creates a http handler from the middleware

type Proxy added in v0.0.38

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

Proxy is a multi-host reverse proxy

func NewProxy added in v0.0.38

func NewProxy(version string) *Proxy

NewProxy creates a new multi-host reverse proxy

func (*Proxy) Direct added in v0.0.38

func (p *Proxy) Direct(pathPrefix, host string) error

Direct sets a new director for the path e.g., pathPrefix is typically the name of the microservice

func (*Proxy) Middleware added in v0.0.38

func (p *Proxy) Middleware(middlewares ...Middleware)

Middleware adds a middleware to the proxy

func (*Proxy) ServeHTTP added in v0.0.38

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RouteHandler added in v0.2.5

type RouteHandler interface {
	Route(method, endpoint string, handlerFunc http.HandlerFunc, middlewares ...Middleware)
}

RouteHandler a handler for routing http requests

type Router

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

Router is an instance of a mux based Router

func NewRouter

func NewRouter(major int, version string, opts ...RouterOption) *Router

NewRouter constructs a new mux based Router

func (*Router) Middleware

func (r *Router) Middleware(middlewares ...Middleware)

Middleware adds a handler to execute before/after the principle request handler

func (*Router) Route added in v0.0.36

func (r *Router) Route(method, endpoint string, handlerFunc http.HandlerFunc, middlewares ...Middleware)

Route adds a handler for the http method and endpoint

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RouterOption added in v0.2.0

type RouterOption func(r *Router)

RouterOption is a handler for configuring the router

func WithServicePrefix added in v0.2.0

func WithServicePrefix(prefix string) RouterOption

WithServicePrefix creates a service prefix option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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