rest

package
v0.9.9-rc8 Latest Latest
Warning

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

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

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