api

package
v0.23.9 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APInterface

type APInterface interface {
	Head(string, ...*Handler)   // Associate handlers with the HEAD HTTP method.
	Get(string, ...*Handler)    // Associate handlers with the GET HTTP method.
	Post(string, ...*Handler)   // Associate handlers with the POST HTTP method.
	Put(string, ...*Handler)    // Associate handlers with the PUT HTTP method.
	Patch(string, ...*Handler)  // Associate handlers with the PATCH HTTP method.
	Delete(string, ...*Handler) // Associate handlers with the DELETE HTTP method.
}

APInterface defines the interface for an API router. It specifies methods for associating handlers with HTTP methods and URL paths.

func Make

func Make(cfg *Config) APInterface

Make creates an instance of the API based on the provided configuration. It initializes the Router with the deprecation status and empty handler maps for each HTTP method.

Parameters: - cfg: *Config Configuration data used to set up the router.

Returns: - APInterface: An instance of Router fulfilling the APInterface.

type Config

type Config struct {
	Depreciated bool   // Indicates if the API is deprecated.
	Version     string // The version of the API.
}

Config represents the configuration for an API. It holds settings that affect the behavior of the API, such as deprecation status and version.

type Handler

type Handler = func() error

Handler is a function type that represents an API handler. Each handler is a function that returns an error, allowing for error handling in API operations.

type Router

type Router struct {
	Depreciated bool // Indicates if the router is deprecated.
	// contains filtered or unexported fields
}

Router represents your API. It manages the association of URL paths with their corresponding handlers based on HTTP methods like GET, POST, PUT, PATCH, and DELETE. The Router also keeps track of whether it is deprecated.

func MakeRouter

func MakeRouter() *Router

MakeRouter creates and returns a new instance of Router. This function initializes a Router with its default values.

Returns: - *Router: A new instance of Router.

func (*Router) Delete

func (r *Router) Delete(url string, handlers ...*Handler)

Delete associates one or more handlers with the DELETE method. It allows for setting up handlers to respond to DELETE requests on a given URL path.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

func (*Router) Get

func (r *Router) Get(url string, handlers ...*Handler)

Get associates one or more handlers with the GET method. Similar to Head, this method allows adding handlers that respond to GET requests.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

func (*Router) Head

func (r *Router) Head(url string, handlers ...*Handler)

Head associates one or more handlers with the HEAD method. This method allows adding handlers to the router that respond to HEAD requests for a specific URL path.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

func (*Router) Patch

func (r *Router) Patch(url string, handlers ...*Handler)

Patch associates one or more handlers with the PATCH method. This method facilitates adding handlers for PATCH requests to the router.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

func (*Router) Post

func (r *Router) Post(url string, handlers ...*Handler)

Post associates one or more handlers with the POST method. This method is used for associating handlers that handle POST requests.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

func (*Router) Put

func (r *Router) Put(url string, handlers ...*Handler)

Put associates one or more handlers with the PUT method. It allows for handlers that manage PUT requests to be linked to a specific URL path.

Parameters: - url: string The URL path to associate with the handlers. - handlers: ...*Handler The handlers to be associated with the URL path.

Jump to

Keyboard shortcuts

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