servekit

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 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 a breaking changes until v1.0.0.

Docs

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

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
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