Documentation ¶
Index ¶
- type APInterface
- type Config
- type Handler
- type Router
- func (r *Router) Delete(url string, handlers ...*Handler)
- func (r *Router) Get(url string, handlers ...*Handler)
- func (r *Router) Head(url string, handlers ...*Handler)
- func (r *Router) Patch(url string, handlers ...*Handler)
- func (r *Router) Post(url string, handlers ...*Handler)
- func (r *Router) Put(url string, handlers ...*Handler)
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.