httpds

package
v0.0.0-...-c5cc7cd Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Request  *http.Request
	Response *http.Response
	Error    error
	// contains filtered or unexported fields
}

Context is the core of data sources. It allows us to pass variables between handlers and manage the flow of a request

func NewContext

func NewContext(handlers ...Plugin) *Context

NewContext creates a new context and initializes the handler chain

func (Context) FullPath

func (c Context) FullPath() string

FullPath returns the request templated path

func (*Context) Handle

func (c *Context) Handle()

Handle runs the main handler in the handler chain

func (*Context) Next

func (c *Context) Next()

Next runs the next handler in the handler chain

func (*Context) Use

func (c *Context) Use(handlers ...Plugin)

Use adds a new handler to the handler chain

type DataSource

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

DataSource is a component that one can use to encapsulate fetching data from a source, in this case: a REST API. Create an instance of DataSource by using New() or Default().

func New

func New(client *http.Client, plugins ...Plugin) DataSource

New returns a new blank DataSource configured with a given HTTP client and a list of plugins.

func (*DataSource) Do

func (ds *DataSource) Do(ctx context.Context, path string, req *http.Request) (*http.Response, error)

Do builds the request context, prepares the Context handler chain and runs the main handler. It provides the same exact features as Client.Do.

type Plugin

type Plugin func(c *Context)

Plugin defines the handler used by datasource as return value.

Jump to

Keyboard shortcuts

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