Documentation
¶
Index ¶
- Constants
- Variables
- func Fake[T any](impl any) fakeComponent
- func Run[T any, _ PointerToMain[T]](ctx context.Context, run func(context.Context, *T) error, ...) error
- func RunTest[T any](tb testing.TB, body func(context.Context, T), opts ...func(*options))
- func RunTest2[T1, T2 any](tb testing.TB, body func(context.Context, T1, T2), opts ...func(*options))
- func RunTest3[T1, T2, T3 any](tb testing.TB, body func(context.Context, T1, T2, T3), opts ...func(*options))
- func WithConfigFile(filename string) func(*options)
- func WithFakes(fakes ...fakeComponent) func(*options)
- func WithInterceptors(interceptors ...interceptor.Interceptor) func(*options)
- func WithLogWrapper(h func(slog.Handler) slog.Handler) func(*options)
- func WithOpenTelemetryDisabled() func(*options)
- func WithRegistrations(regs ...*Registration) func(*options)
- type Implements
- type InstanceOf
- type Kod
- type LazyInit
- type LocalStubFnInfo
- type Main
- type ObservedLogs
- type PointerToMain
- type Ref
- type Registration
- type WithConfig
- type WithGlobalConfig
Constants ¶
const (
PkgPath = "github.com/go-kod/kod"
)
Variables ¶
var NewLogObserver = kslog.NewLogObserver
var Register = registry.Register
Register registers the given component implementations.
Functions ¶
func Run ¶
func Run[T any, _ PointerToMain[T]](ctx context.Context, run func(context.Context, *T) error, opts ...func(*options)) error
Run initializes and runs the application with the provided main component and options.
func RunTest2 ¶ added in v0.7.0
func RunTest2[T1, T2 any](tb testing.TB, body func(context.Context, T1, T2), opts ...func(*options))
RunTest2 runs a test function with two components.
func RunTest3 ¶ added in v0.7.0
func RunTest3[T1, T2, T3 any](tb testing.TB, body func(context.Context, T1, T2, T3), opts ...func(*options))
RunTest3 runs a test function with three components.
func WithConfigFile ¶
func WithConfigFile(filename string) func(*options)
WithConfigFile is an option setter for specifying a configuration file.
func WithFakes ¶
func WithFakes(fakes ...fakeComponent) func(*options)
WithFakes is an option setter for specifying fake components for testing.
func WithInterceptors ¶ added in v0.6.0
func WithInterceptors(interceptors ...interceptor.Interceptor) func(*options)
WithInterceptors is an option setter for specifying interceptors.
func WithLogWrapper ¶
WithLogWrapper is an option setter for specifying a logger.
func WithOpenTelemetryDisabled ¶ added in v0.9.1
func WithOpenTelemetryDisabled() func(*options)
WithOpenTelemetryDisabled is an option setter for disabling OpenTelemetry.
func WithRegistrations ¶
func WithRegistrations(regs ...*Registration) func(*options)
WithRegistrations is an option setter for specifying component registrations.
Types ¶
type Implements ¶
type Implements[T any] struct { // contains filtered or unexported fields }
Implements[T any] provides a common structure for components, with logging capabilities and a reference to the component's interface.
type InstanceOf ¶
type InstanceOf[T any] interface { // contains filtered or unexported methods }
InstanceOf[T any] is an interface for asserting implementation of an interface T.
type Kod ¶
type Kod struct {
// contains filtered or unexported fields
}
Kod represents the core structure of the application, holding configuration and component registrations.
func FromContext ¶
FromContext returns the Kod value stored in ctx, if any.
type LazyInit ¶ added in v0.10.0
type LazyInit struct{}
LazyInit is a marker type for lazy initialization of components.
type LocalStubFnInfo ¶
type LocalStubFnInfo = registry.LocalStubFnInfo
LocalStubFnInfo is the information passed to LocalStubFn.
type Main ¶
type Main interface{}
Main is the interface that should be implemented by an application's main component. The main component is the entry point of the application, and is expected to be a struct that embeds Implements[Main].
Example:
type app struct { kod.Implements[kod.Main] } func main() { kod.Run(context.Background(), func(ctx context.Context, main *app) error { fmt.Println("Hello, World!") return nil }) }
type ObservedLogs ¶
type ObservedLogs kslog.ObservedLogs
type PointerToMain ¶
type PointerToMain[T any] interface { *T InstanceOf[Main] }
PointerToMain is a type constraint that asserts *T is an instance of Main (i.e. T is a struct that embeds weaver.Implements[weaver.Main]).
type Ref ¶
type Ref[T any] struct { // contains filtered or unexported fields }
Ref[T any] is a reference holder to a value of type T. The reference is expected to be a field of a component struct. The value is set by the framework, and is accessible via the Get() method.
Example:
type app struct { kod.Implements[kod.Main] component kod.Ref[example.Component] } func main() { kod.Run(context.Background(), func(ctx context.Context, main *app) error { component := main.component.Get() // ... }) }
type Registration ¶
type Registration = registry.Registration
Registration is the registration information for a component.
type WithConfig ¶
type WithConfig[T any] struct { // contains filtered or unexported fields }
WithConfig[T any] is a struct to hold configuration of type T. The struct is expected to be a field of a component struct. The configuration is loaded from a file, and is accessible via the Config() method.
Example:
type app struct { kod.Implements[kod.Main] kod.WithConfig[appConfig] } type appConfig struct { Host string Port int } func main() { kod.Run(context.Background(), func(ctx context.Context, main *app) error { fmt.Println("config:", main.Config()) }) }
func (*WithConfig[T]) Config ¶
func (wc *WithConfig[T]) Config() *T
Config returns a pointer to the config.
type WithGlobalConfig ¶ added in v0.12.0
type WithGlobalConfig[T any] struct { // contains filtered or unexported fields }
func (*WithGlobalConfig[T]) Config ¶ added in v0.12.0
func (wc *WithGlobalConfig[T]) Config() *T
Config returns a pointer to the config.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
kod/internal
Package files contains file-related utilities.
|
Package files contains file-related utilities. |
examples
module
|
|
ext
module
|
|
internal
|
|
tests
module
|