Documentation
¶
Overview ¶
Package fundamentals is the root of the Go counterpart of Cratis Fundamentals.
Package concepts provides the shared UUID and temporal wire scalars and the typed concept contract; package correlation shares correlation IDs through context.Context; package dependencyinjection provides an optional dependency-injection contract and default container. Documentation/parity.md records the remaining gaps.
Example (CorrelationPropagation) ¶
package main
import (
"context"
"fmt"
"github.com/cratis/fundamentals.go/concepts"
"github.com/cratis/fundamentals.go/correlation"
)
func main() {
id, err := concepts.ParseUUID("00112233-4455-6677-8899-aabbccddeeff")
if err != nil {
panic(err)
}
operation, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := correlation.WithID(operation, id)
// Pass ctx to the next operation; the parent remains unchanged.
fmt.Println("save author:", correlation.FromContext(ctx))
fmt.Println("parent unset:", correlation.FromContext(operation).IsZero())
cleared := correlation.WithID(ctx, correlation.ID{})
fmt.Println("child unset:", correlation.FromContext(cleared).IsZero())
cancel()
fmt.Println("canceled:", cleared.Err() == context.Canceled)
}
Output: save author: 00112233-4455-6677-8899-aabbccddeeff parent unset: true child unset: true canceled: true
Example (DomainRoundTrip) ¶
package main
import (
"encoding/json"
"fmt"
"github.com/cratis/fundamentals.go/concepts"
)
// AuthorID identifies an author without making arbitrary UUIDs interchangeable.
type AuthorID concepts.UUID
func (id AuthorID) ConceptValue() concepts.UUID { return concepts.UUID(id) }
func (id AuthorID) MarshalText() ([]byte, error) { return concepts.UUID(id).MarshalText() }
func (id AuthorID) MarshalJSON() ([]byte, error) { return concepts.UUID(id).MarshalJSON() }
func (id *AuthorID) UnmarshalText(data []byte) error {
return (*concepts.UUID)(id).UnmarshalText(data)
}
func (id *AuthorID) UnmarshalJSON(data []byte) error {
return (*concepts.UUID)(id).UnmarshalJSON(data)
}
func main() {
id, err := concepts.ParseUUID("00112233-4455-6677-8899-AABBCCDDEEFF")
if err != nil {
panic(err)
}
type author struct {
ID AuthorID `json:"id"`
Name string `json:"name"`
}
original := author{ID: AuthorID(id), Name: "Ada"}
data, err := json.Marshal(original)
if err != nil {
panic(err)
}
var restored author
if err := json.Unmarshal(data, &restored); err != nil {
panic(err)
}
fmt.Println(string(data))
fmt.Println("same author:", restored == original)
}
Output: {"id":"00112233-4455-6677-8899-aabbccddeeff","name":"Ada"} same author: true
Directories
¶
| Path | Synopsis |
|---|---|
|
Package concepts provides portable UUID, DateOnly, TimeOnly and TimeSpan values with .NET-compatible canonical JSON strings and text codecs.
|
Package concepts provides portable UUID, DateOnly, TimeOnly and TimeSpan values with .NET-compatible canonical JSON strings and text codecs. |
|
conceptstypes
Package conceptstypes recognizes typed scalar concepts from go/types metadata for generators and analyzers.
|
Package conceptstypes recognizes typed scalar concepts from go/types metadata for generators and analyzers. |
|
internal/corpus
Package corpus holds declarations shared by reflect and go/types recognition tests.
|
Package corpus holds declarations shared by reflect and go/types recognition tests. |
|
Package correlation shares operation correlation IDs through context.Context.
|
Package correlation shares operation correlation IDs through context.Context. |
|
Package dependencyinjection defines container-neutral exact-type registration, resolution and scope contracts.
|
Package dependencyinjection defines container-neutral exact-type registration, resolution and scope contracts. |
|
bindingtypes
Package bindingtypes plans constructor registrations over already type-checked Go packages.
|
Package bindingtypes plans constructor registrations over already type-checked Go packages. |
|
container
Package container implements the optional default dependency injection provider.
|
Package container implements the optional default dependency injection provider. |
|
ditest
Package ditest provides reusable dependency injection conformance suites.
|
Package ditest provides reusable dependency injection conformance suites. |
|
internal/bindingcorpus/competitor
Package competitor adds constructorless, ignored structural competition.
|
Package competitor adds constructorless, ignored structural competition. |
|
internal/bindingcorpus/declarationcompetitor
Package declarationcompetitor exposes constructorless generic competitors.
|
Package declarationcompetitor exposes constructorless generic competitors. |
|
internal/bindingcorpus/directives
Package directives supplies valid type-attached policies.
|
Package directives supplies valid type-attached policies. |
|
internal/bindingcorpus/forms
Package forms supplies constructor shapes.
|
Package forms supplies constructor shapes. |
|
internal/bindingcorpus/genericcompetitor
Package genericcompetitor supplies open structural implementation families.
|
Package genericcompetitor supplies open structural implementation families. |
|
internal/bindingcorpus/genericforward
Package genericforward exposes a closed generic convention implementation.
|
Package genericforward exposes a closed generic convention implementation. |
|
internal/bindingcorpus/invaliddirectives
Package invaliddirectives supplies conflicting and misplaced comments.
|
Package invaliddirectives supplies conflicting and misplaced comments. |
|
internal/bindingcorpus/render
Package render supplies a runtime fixture for hand-authored product rendering.
|
Package render supplies a runtime fixture for hand-authored product rendering. |
|
internal/bindingcorpus/renderfailure
Package renderfailure supplies analyzed runtime ownership regressions.
|
Package renderfailure supplies analyzed runtime ownership regressions. |
|
internal/bindingcorpus/unique
Package unique supplies a unique pointer-method-set convention pair.
|
Package unique supplies a unique pointer-method-set convention pair. |
|
internal/value
Package value centralizes runtime validation for contracts and container adapters.
|
Package value centralizes runtime validation for contracts and container adapters. |
|
internal
|
|
|
typeinspection
Package typeinspection supplies non-mutating views of checked Go types.
|
Package typeinspection supplies non-mutating views of checked Go types. |
|
Package naming shares Cratis Fundamentals' acronym-friendly camel casing, first-character Pascal casing, and explicit naming policies.
|
Package naming shares Cratis Fundamentals' acronym-friendly camel casing, first-character Pascal casing, and explicit naming policies. |
Click to show internal directories.
Click to hide internal directories.