servekit

package module
v0.2.41 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 5 Imported by: 0

README

The servkit helps to build APIs

Is a set of well-tested (or not well 🤭) reusable components to speedup day-to-day development of HTTP and gRPC APIs.

⚠️ Under Construction: There could be breaking changes until v1.0.0.

Docs

The code should be very straightforward to read, but you always can check the go docs.

Packages

  • authkit - Authentication and authorization utilities for securing your API endpoints
  • ctxkit - Context management utilities and helpers for request context handling
  • dbkit - Database utilities and helpers for working with various databases (PostgreSQL, SQLite)
  • errkit - Error handling utilities and custom error types for better error management
  • grpckit - gRPC server utilities and middleware for building gRPC services
  • httpkit - HTTP server utilities, middleware, and helpers for building HTTP APIs
  • idkit - ID generation utilities using ULID for unique identifier generation
  • logkit - Logging utilities and structured logging helpers
  • mailkit - Email sending utilities and templates for handling email communications
  • respond - Response formatting utilities for consistent API responses
  • retry - Retry mechanisms and backoff strategies for handling transient failures
  • slackkit - Slack integration utilities for sending notifications and messages
  • tern - Ternary operator

On the shoulders of giants

Contributing guidelines

You can find our guidelines here.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error represents a package level error. Implements builtin error interface.

const (
	// ErrGracefullyShutdown represents an error message
	// indicating the failure to gracefully shut down a listener.
	ErrGracefullyShutdown Error = "shut down listener gracefully"

	// ErrCertPathRequired represents an error message
	// indicating that a certificate file path is required.
	ErrCertPathRequired Error = "certificate file path is required"

	// ErrPrivateKeyPathRequired represents an error message
	// indicating that a private key file path is required.
	ErrPrivateKeyPathRequired Error = "private key file path is required"
)

func (Error) Error

func (e Error) Error() string

type Listener

type Listener interface {
	// Serve runs the listener, handling incoming requests. It takes a context as an argument
	// and returns an error if an error occurs while serving requests.
	Serve(ctx context.Context) error
}

Listener is an interface that represents a listener which can serve requests. It requires the implementation of the Serve method that takes a context and returns an error.

type Server

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

Server is a type that represents a server that holds a map of listeners.

func NewServer

func NewServer(logger *slog.Logger) *Server

NewServer creates a new Server instance with an empty listeners map and returns a pointer to the created Server.

func (*Server) RegisterListener

func (s *Server) RegisterListener(name string, listener Listener)

RegisterListener adds a listener to the Server's listeners map.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve runs the server and serves requests from all listeners. It creates an error group and a listener context. It iterates through the listeners map and starts a goroutine for each listener. Each goroutine retries calling the listener's Serve method until it succeeds or the retry limit is reached. If the Serve method returns an error, it logs an error message and checks if the error is retryable. If the context is canceled, it returns the context error. If the retry limit is reached, it returns ErrRetryLimitReached. Finally, it waits for all goroutines to complete and returns any error encountered during serving.

Directories

Path Synopsis
authkit
dbkit
Package idkit provides the set of functions to generate different kind of identifiers.
Package idkit provides the set of functions to generate different kind of identifiers.

Jump to

Keyboard shortcuts

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