package
0.0.0-20241224225423-d9c92e7a94cf
Repository: https://github.com/softika/gopherizer.git
Documentation: pkg.go.dev

# README

API package documentation

The api package implements the API layer of the application, providing a structured approach to manage HTTP servers, routes, handlers, and request/response mappings.

Components

Server

The Server struct manages the lifecycle of the HTTP server. It is responsible for:

  • Listening for incoming requests.
  • Serving responses via the http.Server.
  • Gracefully shutting down the server when required.

This component is highly configurable, allowing you to set:

  • Server address and port.
  • Read and write timeouts.

Router

The default router is based on the lightweight Chi router, which can be replaced with any router implementing the http.Handler interface.

Features:

Handler

The Handler struct serves as a generic interface for handling incoming HTTP requests. It decouples business logic from the HTTP layer by:

  • Validating and passing the request's context and inputs to the service functions.
  • Returning a response or error from the service functions.

How to Use:

Mappers

The Mappers struct simplifies the process of translating HTTP requests into service-layer inputs and mapping service outputs to HTTP responses.

Key Features:

  • No need to create new handlers for each endpoint.
  • Implement the following interfaces for custom mappings:

Examples:
The mappers package includes examples for handling various types of requests and responses.

# Packages

No description provided by the author

# Functions

NewHandler creates new handler.
No description provided by the author
NewServer creates a new Server.

# Structs

No description provided by the author
Handler is a generic handler type.
Router is the main API router.
No description provided by the author

# Interfaces

RequestMapper is generic interfaces for mapping request objects.
ResponseMapper is generic interfaces for mapping response objects.
No description provided by the author

# Type aliases

HandlerFunc is API generic handler func type.
ServiceFunc is a generic service function type called in a handler.