nitro

package
v0.34.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	// Response is set to true if the procedure is treated as a response.
	Response bool
}

Base can be embedded in a struct to turn it into a procedure.

func (*Base) GetAccessor

func (b *Base) GetAccessor(v interface{}) *stick.Accessor

GetAccessor implements the Key interface.

func (*Base) GetBase

func (b *Base) GetBase() *Base

GetBase implements the Key interface.

type Client

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

Client is a reusable client for accessing procedure endpoints.

func NewClient

func NewClient(baseURL string, httpClient *http.Client) *Client

NewClient will create and return a new client using the provided base URL and custom HTTP client. If the HTTP client is absent, a new one is created.

func (*Client) Call

func (c *Client) Call(ctx context.Context, proc Procedure) error

Call will perform the specified procedure against the endpoint.

type Context

type Context struct {
	context.Context

	// The received procedure.
	Procedure Procedure

	// The current handler.
	Handler *Handler

	// The underlying request.
	Request *http.Request

	// The underlying writer.
	Writer http.ResponseWriter
}

Context allows handlers to interact with the request.

type Endpoint

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

Endpoint manages the calling of procedures.

func NewEndpoint

func NewEndpoint(reporter func(error)) *Endpoint

NewEndpoint creates and returns a new server.

func (*Endpoint) Add

func (s *Endpoint) Add(handler *Handler)

Add will add the specified handler to the endpoint.

func (*Endpoint) Process

func (s *Endpoint) Process(ctx *Context) error

Process handles the specified context.

func (*Endpoint) ServeHTTP

func (s *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type Error

type Error struct {
	// A unique identifier for this particular occurrence of the problem.
	ID string `json:"id,omitempty" bson:"id,omitempty"`

	// A URL that leads to further details about this problem.
	Link string `json:"link,omitempty" bson:"link,omitempty"`

	// The HTTP status code applicable to this problem.
	Status int `json:"status,string,omitempty" bson:"status,string,omitempty"`

	// An application-specific error code.
	Code string `json:"code,omitempty" bson:"code,omitempty"`

	// A short, human-readable summary of the problem.
	Title string `json:"title,omitempty" bson:"title,omitempty"`

	// A human-readable explanation specific to this occurrence of the problem.
	Detail string `json:"detail,omitempty" bson:"detail,omitempty"`

	// A JSON pointer specifying the source of the error.
	//
	// See https://tools.ietf.org/html/rfc6901.
	Source string `json:"source,omitempty" bson:"source,omitempty"`

	// Non-standard meta-information about the error.
	Meta map[string]interface{} `json:"meta,omitempty" bson:"meta,omitempty"`
}

Error objects provide additional information about problems encountered while performing an operation.

func AsError

func AsError(err error) *Error

AsError will try to unwrap an Error from err.

func BadRequest

func BadRequest(detail, source string) *Error

BadRequest returns a new bad request error with a source.

func ErrorFromStatus

func ErrorFromStatus(status int, detail string) *Error

ErrorFromStatus will return an error that has been derived from the passed status code.

Note: If the passed status code is not a valid HTTP status code, an Internal Server Error status code will be used instead.

func (*Error) Error

func (e *Error) Error() string

Error returns a string representation of the error for logging purposes.

type Handler

type Handler struct {
	// The handled procedure.
	Procedure Procedure

	// The request body limit.
	//
	// Default: 4K.
	Limit int64

	// The processing callback.
	Callback func(ctx *Context) error
}

Handler defines a procedure handler.

type Meta

type Meta struct {
	// The values type.
	Type reflect.Type

	// The name.
	Name string

	// The used transfer coding.
	Coding stick.Coding

	// The accessor.
	Accessor *stick.Accessor
}

Meta contains meta information about a procedure.

func GetMeta

func GetMeta(proc Procedure) *Meta

GetMeta will parse the keys "nitro" tag on the embedded nitro.Base struct and return the meta object.

func (*Meta) Make

func (i *Meta) Make() Procedure

Make creates a new instance of the procedure.

type Procedure

type Procedure interface {
	Validate() error
	GetBase() *Base
	GetAccessor(interface{}) *stick.Accessor
}

Procedure denotes a request response object.

Jump to

Keyboard shortcuts

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