Tier: Foundational · Status: Full · Java original:
firefly-common· .NET project:FireflyFramework.Kernel
kernel is the shared-vocabulary tier of the framework. It exposes
the four primitives every Firefly module agrees on:
- The RFC 7807
ProblemDetailenvelope. - The generic
Result[T]success-or-failure wrapper. - The
Clockabstraction for testable time. - The
FireflyErrortyped exception family.
Every method in every other module returns one of these types. The
wire-shape is identical to the Java firefly-common module and the .NET
FireflyFramework.Kernel project — a service running version X on
any of the three runtimes emits the same JSON.
Java's Throwable hierarchy and .NET's Exception family are stable
language fixtures. Go's error interface is intentionally minimal —
which means every framework that wants typed error codes / structured
fields / HTTP status mapping has to invent its own. kernel provides
the canonical type so the whole platform agrees, and so the wire is
identical across runtimes.
The canonical application/problem+json envelope.
| Member | Behaviour |
|---|---|
Type |
URI reference identifying the problem class |
Title |
Short, human-readable summary |
Status |
HTTP status code |
Detail |
Specific to this occurrence |
Instance |
URI of the request that produced the problem |
Extensions |
RFC 7807 §3.2 extension members; flattened on MarshalJSON |
Constructors emit the canonical type URIs (https://fireflyframework.org/problems/<kind>):
ProblemBadRequest, ProblemUnauthorized, ProblemForbidden,
ProblemNotFound, ProblemConflict, ProblemUnprocessable,
ProblemRateLimited, ProblemInternal, ProblemValidation.
Generic success-or-failure envelope. Use the (value T, err error)
return idiom in normal Go code; reach for Result[T] only at module
boundaries that pass a single value through pipelines.
r := kernel.Ok(42)
v, err := r.Value() // 42, nil
mapped := kernel.MapResult(r, strconv.Itoa) // Result[string]type Clock interface { Now() time.Time }Implementations: SystemClock, FixedClock{T: ...}, MutableClock
(thread-safe; Advance(d) for tests).
type FireflyError struct {
Code string
Title string
Status int
Detail string
Fields map[string]any
Cause error
}Constructors NewBadRequest(...), NewUnauthorized(...),
NewForbidden(...), NewNotFound(...), NewConflict(...),
NewValidation(...), NewRateLimited(...), NewInternal(...),
NewIdempotencyConflict(...) return values that errors.Is /
errors.As correctly. Helpers: IsFirefly(err), StatusOf(err),
AsProblem(err) (renders any error as a ProblemDetail).
ctx = kernel.WithCorrelationID(ctx, "abc-123")
id, ok := kernel.CorrelationIDFrom(ctx)
fresh := kernel.NewCorrelationID() // 32-char hexHeaderCorrelationID (X-Correlation-Id) and HeaderIdempotencyKey
(Idempotency-Key) are exported for cross-module agreement.
kernel.Version is the released framework version
("26.05.01" at the time of writing) — embedded in the actuator
/version payload and the startup banner.
import (
"errors"
"github.com/fireflyframework/fireflyframework-go/kernel"
)
func charge(orderID string) error {
if orderID == "" {
return kernel.NewBadRequest("order id required").WithField("field", "orderId")
}
// … domain logic …
return nil
}
// In a handler:
if err := charge(""); err != nil {
var fe *kernel.FireflyError
if errors.As(err, &fe) {
// Use fe.Status (400) and fe.ToProblem() to render RFC 7807.
}
}cd kernel
go test ./...Suite covers JSON round-trip on ProblemDetail (with extension
flattening), Result[T] map / flat-map, every FireflyError
constructor, the clock variants, and correlation-id context propagation.