Skip to content

Latest commit

 

History

History
99 lines (79 loc) · 2.69 KB

File metadata and controls

99 lines (79 loc) · 2.69 KB

startercore

Tier: Starter · Status: Full · Java original: firefly-starter-core · .NET project: FireflyFramework.Starter.Core

Overview

startercore is the one-call infrastructure-tier wiring for any Firefly Go service. A single New(Config{...}) returns a Core struct holding every component a typical service needs:

  • Loggerslog.Logger with correlation-id enrichment.
  • Cachecache.Adapter, default Memory.
  • Buscqrs.Bus with the ValidationMiddleware pre-installed.
  • Brokereda.Broker, default InMemory.
  • Healthobservability.Composite with a default cache health indicator.
  • Idempotencyweb.IdempotencyConfig.
  • Metricsactuator.Registry.
  • Schedulerscheduling.Scheduler.

Plus four convenience methods:

  • Middleware() — the canonical outermost HTTP middleware chain (problem renderer, correlation, idempotency).
  • ActuatorHandler(infoContributors...) — pre-wired /actuator/{health,info,metrics,env,goroutines,version} mux.
  • NewApplication()lifecycle.Application pre-configured with the core's logger.
  • PrintBanner() — emits the ASCII banner identifying app + version
    • runtime.

Public surface

type Config struct {
    AppName     string
    AppVersion  string
    StarterName string
    Logger      *slog.Logger
    Cache       cache.Adapter
    Bus         *cqrs.Bus
    Broker      eda.Broker
    Health      *observability.Composite
    Idempotency *web.IdempotencyConfig
    Metrics     *actuator.Registry
    Scheduler   *scheduling.Scheduler
}

type Core struct { ... }
func New(Config) *Core

func (*Core) Middleware() func(http.Handler) http.Handler
func (*Core) ActuatorHandler(infoContributors ...func() map[string]any) http.Handler
func (*Core) NewApplication() *lifecycle.Application
func (*Core) PrintBanner()

Quick start

import (
    "context"
    "net/http"
    "os/signal"
    "syscall"

    "github.com/fireflyframework/fireflyframework-go/startercore"
)

func main() {
    core := startercore.New(startercore.Config{
        AppName:    "orders",
        AppVersion: "1.0.0",
    })

    apiMux   := http.NewServeMux()
    adminMux := http.NewServeMux()
    adminMux.Handle("/actuator/", core.ActuatorHandler())

    core.PrintBanner()
    app := core.NewApplication().
        OnHTTP(":8080", core.Middleware()(apiMux)).
        OnHTTP(":8081", adminMux)

    ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
    defer cancel()
    _ = app.Run(ctx)
}

Testing

cd startercore
go test ./...

Covers every default component being non-nil, the panic→500 middleware chain, and the banner content.