factory

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 1 Imported by: 0

README

Factory

The Factory package implements the Factory design pattern for various components of the Boost framework, facilitating the creation and configuration of complex objects. This package is fundamental to the modular and extensible architecture of the framework.

Overview

Factory provides a standardized approach to instantiate objects, allowing client code to request objects without knowing the specific details of how they are created. This promotes decoupling between components and facilitates system extensibility.

Main Components

Core

The core subpackage contains factory implementations for fundamental system components, organized into categories:

  • Database: Factories for database connections and operations
  • Net: Components related to networks and communication
  • Time: Utilities related to time and scheduling
Contrib

The contrib directory contains factory implementations for integration with third-party libraries and frameworks, including:

  • gRPC: For communication between services
  • go-chi/chi: net/http router (v5)
  • gofiber/fiber: fasthttp web framework (v2)
  • valyala/fasthttp: fasthttp client (v1)
  • mittwald/vaultgo: Vault client and credential managers for redis, elasticsearch and mongo (v0)
  • Azure (azure-sdk-for-go): token credential and Blob Storage client (v1)
  • storj/drpc: lightweight drop-in replacement for gRPC, server and client (v1)
  • MCP (modelcontextprotocol/go-sdk): Model Context Protocol server and client
  • Google Cloud Platform (GCP): Integration with GCP services
  • Confluent: For working with Apache Kafka
  • segmentio/kafka-go: Apache Kafka in pure Go (no cgo)
  • Ollama: Integration with AI models
  • Spf13/Cobra: For creating command-line interfaces
Local

The local subpackage provides specific implementations for local use or development environments, facilitating testing and rapid prototyping.

How to Use

To use the Factory package in your application:

  1. Import the specific subpackage that contains the desired factory
  2. Configure the necessary parameters
  3. Use the factory to create instances of the required objects

Plugins

Factories accept plugins as a variadic argument and run them right after building the component. The contract lives in this package:

// Plugin customizes a component T built by a factory.
type Plugin[T any] func(context.Context, T) error

// ApplyPlugins runs plugins in order and stops at the first error.
func ApplyPlugins[T any](ctx context.Context, target T, plugins ...Plugin[T]) error

The per-factory plugin types are aliases of it, so a plugin written against either name is interchangeable:

Factory Alias
contrib/redis/go-redis/v9 Plugin = factory.Plugin[*redis.Client], ClusterPlugin = factory.Plugin[*redis.ClusterClient]
contrib/labstack/echo/v4, v5 Plugin = factory.Plugin[*Server]
contrib/go-chi/chi/v5 Plugin = factory.Plugin[*Server]
contrib/gofiber/fiber/v2 Plugin = factory.Plugin[*Server]
contrib/go-resty/resty/v2 Plugin = factory.Plugin[*resty.Client]
contrib/valyala/fasthttp/v1/client Plugin = factory.Plugin[*fasthttp.Client]
contrib/storj.io/drpc/v1/server Plugin = factory.Plugin[*Server]
contrib/storj.io/drpc/v1/client Plugin = factory.Plugin[*drpcconn.Conn]
contrib/elastic/go-elasticsearch/v8, v9 Plugin = factory.Plugin[*elasticsearch.Client]
contrib/gocql/gocql/v1, contrib/apache/cassandra-gocql-driver/v2 Plugin = factory.Plugin[*gocql.Session]
contrib/aws/aws-sdk-go-v2/v1 Plugin = factory.Plugin[*aws.Config]
contrib/azure/azure-sdk-for-go/v1/client/azblob Plugin = factory.Plugin[*azblob.ClientOptions]
contrib/go.mongodb.org/mongo-driver/v1, v2 ClientOptionsPlugin = factory.Plugin[*options.ClientOptions], ClientPlugin = factory.Plugin[*mongo.Client]

Factories whose plugins have a different shape (gRPC, NATS, Hystrix, the mongo Plugin pair) keep their own types.

Plugin packages sit under each factory's plugins/ directory: contrib/ integrates a third-party library, native/ wraps the upstream library's own middleware, extra/ is boost-authored and generic, and local/ wires another boost package (health, log, cache).

The gocql health checker (contrib/gocql/gocql/v1/plugins/local/extra/health) runs SELECT now() FROM system.local with the context of the check, a query every cassandra and scylla node answers.

Integration with Other Packages

The Factory integrates with other components of the Boost framework:

  • Bootstrap: For application initialization
  • Wrapper: For configuration and logging
  • Model: For data structure definitions

Extensibility

The Factory package was designed to be easily extensible. To add support for new libraries or frameworks:

  1. Create a new subpackage in contrib with the name of the library
  2. Implement the necessary factory interfaces
  3. Add appropriate tests and documentation

Contribution

Contributions to the Factory package are welcome. When contributing, make sure to follow the code standards and add appropriate tests for new functionalities.

Documentation

Overview

Package factory holds the contract shared by every factory under it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPlugins

func ApplyPlugins[T any](ctx context.Context, target T, plugins ...Plugin[T]) error

ApplyPlugins runs plugins against target in order and stops at the first error, returning it.

Types

type Plugin

type Plugin[T any] func(context.Context, T) error

Plugin customizes a component T built by a factory (a client, a server, a config). Factories accept plugins as a variadic argument and run them right after building the component.

Directories

Path Synopsis
contrib
apache/cassandra-gocql-driver/v2
Package gocql builds Cassandra sessions with the gocql v2 driver (github.com/apache/cassandra-gocql-driver/v2), configured under boost.factory.gocql.* -- the keys of the gocql v1 factory (factory/contrib/gocql/gocql/v1), so moving to v2 only changes the import.
Package gocql builds Cassandra sessions with the gocql v2 driver (github.com/apache/cassandra-gocql-driver/v2), configured under boost.factory.gocql.* -- the keys of the gocql v1 factory (factory/contrib/gocql/gocql/v1), so moving to v2 only changes the import.
apache/cassandra-gocql-driver/v2/plugins/local/extra/health
Package health registers a gocql v2 session as a checker of github.com/xgodev/boost/extra/health, configured under boost.factory.gocql.plugins.health.*.
Package health registers a gocql v2 session as a checker of github.com/xgodev/boost/extra/health, configured under boost.factory.gocql.plugins.health.*.
elastic/go-elasticsearch/v9
Package elasticsearch is boost's factory for the go-elasticsearch v9 client: options under boost.factory.elasticsearch, a ping on creation and plugins run on the built client.
Package elasticsearch is boost's factory for the go-elasticsearch v9 client: options under boost.factory.elasticsearch, a ping on creation and plugins run on the built client.
elastic/go-elasticsearch/v9/plugins/local/extra/health
Package health registers a go-elasticsearch v9 client in boost's extra/health: the checker pings the cluster, and an error status fails it.
Package health registers a go-elasticsearch v9 client in boost's extra/health: the checker pings the cluster, and an error status fails it.
go-resty/resty/v2/plugins/contrib/dubonzi/otelresty/v1
This package implements integration between the go-resty (https://github.com/go-resty/resty) library and OpenTelemetry.
This package implements integration between the go-resty (https://github.com/go-resty/resty) library and OpenTelemetry.
go.mongodb.org/mongo-driver/v1/plugins/contrib/go.opentelemetry.io/contrib/v0
This package implements integration between the official go mongodb driver (https://github.com/mongodb/mongo-go-driver) and OpenTelemetry.
This package implements integration between the official go mongodb driver (https://github.com/mongodb/mongo-go-driver) and OpenTelemetry.
go.mongodb.org/mongo-driver/v2/plugins/contrib/go.opentelemetry.io/contrib/v0
This package implements integration between the official go mongodb driver (https://github.com/mongodb/mongo-go-driver) and OpenTelemetry.
This package implements integration between the official go mongodb driver (https://github.com/mongodb/mongo-go-driver) and OpenTelemetry.
labstack/echo/v4/plugins/contrib/go.opentelemetry.io/contrib/v0
This package implements integration between echo (https://github.com/labstack/echo) and OpenTelemetry.
This package implements integration between echo (https://github.com/labstack/echo) and OpenTelemetry.
labstack/echo/v5/plugins/contrib/swaggo/echo-swagger/v2
Package swagger serves the Swagger UI and the swag docs on an echo v5 server, through github.com/swaggo/echo-swagger/v2.
Package swagger serves the Swagger UI and the swag docs on an echo v5 server, through github.com/swaggo/echo-swagger/v2.
modelcontextprotocol/go-sdk/v1/client/plugins/contrib/go.opentelemetry.io/otel/v1
Package otel opens an OpenTelemetry span for every MCP call the client sends, propagating the trace to the server in _meta.
Package otel opens an OpenTelemetry span for every MCP call the client sends, propagating the trace to the server in _meta.
modelcontextprotocol/go-sdk/v1/client/plugins/local/wrapper/log
Package log logs every MCP call the client sends through wrapper/log: method, tool, duration and error.
Package log logs every MCP call the client sends through wrapper/log: method, tool, duration and error.
modelcontextprotocol/go-sdk/v1/internal/buildinfo
Package buildinfo reads the application version Go stamps into the binary.
Package buildinfo reads the application version Go stamps into the binary.
modelcontextprotocol/go-sdk/v1/internal/middleware
Package middleware holds the go-sdk middlewares the server and client plugins install: one call in, one log line or span out.
Package middleware holds the go-sdk middlewares the server and client plugins install: one call in, one log line or span out.
modelcontextprotocol/go-sdk/v1/server/plugins/contrib/go.opentelemetry.io/otel/v1
Package otel opens an OpenTelemetry span for every MCP call the server receives, continuing the trace the client sent in _meta.
Package otel opens an OpenTelemetry span for every MCP call the server receives, continuing the trace the client sent in _meta.
modelcontextprotocol/go-sdk/v1/server/plugins/local/wrapper/log
Package log logs every MCP call the server receives through wrapper/log: method, tool, duration and error.
Package log logs every MCP call the server receives through wrapper/log: method, tool, duration and error.
core
local

Jump to

Keyboard shortcuts

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