rest

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package rest provides the implementation of a REST API server using the Huma framework. This package includes server initialization, configuration, middleware setup, and server start/stop functionalities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error424FailedDependency

func Error424FailedDependency(msg string, errs ...error) huma.StatusError

Error424FailedDependency returns a 424.

Types

type Namespace

type Namespace interface {
	// GetName returns the name of the service.
	GetName() ServiceName
	// RegisterHandlers registers the HTTP handlers for the namespace.
	RegisterHandlers() error
}

Namespace defines an interface for service namespaces.

type Response

type Response[T any] struct {
	Body T
}

Response is a generic struct for wrapping API responses.

type Server

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

Server represents a REST API server.

func NewServer

func NewServer(ctx context.Context, dbAdapter db.Adapter, redis *cache.Redis, opts options.Rest) (*Server, error)

NewServer creates a new REST API server instance with the provided context, database adapter, Redis cache, and server options.

Parameters: - ctx: The context to control server lifecycle. - dbAdapter: Database adapter for database interactions. - redis: Redis cache instance for caching. - opts: Server options including OpenAPI configuration and server address.

Returns: - A pointer to the newly created Server instance. - An error if any issue occurs during server creation.

func (*Server) GetAPI

func (s *Server) GetAPI() huma.API

GetAPI returns the Huma API instance associated with the server.

Returns: - The Huma API instance.

func (*Server) GetOptions

func (s *Server) GetOptions() options.Rest

func (*Server) GetRouter

func (s *Server) GetRouter() *chi.Mux

GetRouter returns the HTTP router used by the server.

Returns: - The HTTP router.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for HTTP requests on the specified network address.

Returns: - An error if the server fails to start.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts down the server without interrupting any active connections.

Returns: - An error if the server fails to shut down gracefully.

type ServiceName

type ServiceName string

ServiceName represents the name of a service as a string.

func (ServiceName) String

func (s ServiceName) String() string

String converts the ServiceName to a string.

Jump to

Keyboard shortcuts

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