mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-03 07:06:36 +08:00
feat(plugins): package database, cache, logger, and storage as infra plugins
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package core provides the micro-kernel service bus, generic IoC container, and runtime extensions.
|
||||
package core
|
||||
|
||||
import (
|
||||
|
||||
@@ -36,6 +36,8 @@ type Context struct {
|
||||
|
||||
// NewContext creates a new root Context wrapping a standard Go context.
|
||||
// If base is nil, context.Background() is used by default.
|
||||
//
|
||||
//nolint:contextcheck
|
||||
func NewContext(base context.Context) *Context {
|
||||
if base == nil {
|
||||
base = context.Background()
|
||||
@@ -135,6 +137,8 @@ func (c *Context) Fork() *Context {
|
||||
}
|
||||
|
||||
// ForkWithContext creates a child Context using a specific standard Go context.
|
||||
//
|
||||
//nolint:contextcheck
|
||||
func (c *Context) ForkWithContext(base context.Context) *Context {
|
||||
if base == nil {
|
||||
base = c.goCtx
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package contracts defines unified service interfaces and DTOs for cross-plugin communication.
|
||||
package contracts
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package contracts defines unified service interfaces and DTOs for cross-plugin communication.
|
||||
package contracts
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package contracts defines unified service interfaces and DTOs for cross-plugin communication.
|
||||
package contracts
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package contracts defines unified service interfaces and DTOs for cross-plugin communication.
|
||||
package contracts
|
||||
|
||||
import (
|
||||
|
||||
+5
-1
@@ -9,6 +9,8 @@ import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
const maxHandlerParams = 2
|
||||
|
||||
var ctxInterfaceType = reflect.TypeFor[context.Context]()
|
||||
var errInterfaceType = reflect.TypeFor[error]()
|
||||
|
||||
@@ -62,7 +64,7 @@ func (b *EventBus) On(topic string, handler any) Disposer {
|
||||
}
|
||||
|
||||
numIn := fnType.NumIn()
|
||||
if numIn > 2 {
|
||||
if numIn > maxHandlerParams {
|
||||
panic(fmt.Sprintf("core/events: handler has %d parameters, maximum 2 supported (ctx, event)", numIn))
|
||||
}
|
||||
|
||||
@@ -150,6 +152,8 @@ func Subscribe[T any](bus *EventBus, topic string, handler func(ctx context.Cont
|
||||
// Emit publishes an event to all subscribers of the specified topic.
|
||||
// Handlers are executed synchronously. If any handler panics or returns an error,
|
||||
// the error is collected and returned via errors.Join.
|
||||
//
|
||||
//nolint:contextcheck
|
||||
func (b *EventBus) Emit(ctx context.Context, topic string, payload any) error {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package extpoints defines extension points for router, migrations, tasks, schedules, and settings.
|
||||
package extpoints
|
||||
|
||||
import (
|
||||
|
||||
+35
-15
@@ -72,18 +72,38 @@ type Driver interface {
|
||||
// Disposer is a cleanup function executed when a Context is disposed.
|
||||
type Disposer func() error
|
||||
|
||||
// Re-exported extension point types from core/extpoints for convenient usage.
|
||||
type (
|
||||
RouterExtension = extpoints.RouterExtension
|
||||
RouteDefinition = extpoints.RouteDefinition
|
||||
MigrationExtension = extpoints.MigrationExtension
|
||||
MigrationEntry = extpoints.MigrationEntry
|
||||
TaskExtension = extpoints.TaskExtension
|
||||
TaskDefinition = extpoints.TaskDefinition
|
||||
TaskOption = extpoints.TaskOption
|
||||
ScheduleExtension = extpoints.ScheduleExtension
|
||||
ScheduleDefinition = extpoints.ScheduleDefinition
|
||||
ScheduleOption = extpoints.ScheduleOption
|
||||
SettingExtension = extpoints.SettingExtension
|
||||
SettingSchema = extpoints.SettingSchema
|
||||
)
|
||||
// RouterExtension re-exports extpoints.RouterExtension.
|
||||
type RouterExtension = extpoints.RouterExtension
|
||||
|
||||
// RouteDefinition re-exports extpoints.RouteDefinition.
|
||||
type RouteDefinition = extpoints.RouteDefinition
|
||||
|
||||
// MigrationExtension re-exports extpoints.MigrationExtension.
|
||||
type MigrationExtension = extpoints.MigrationExtension
|
||||
|
||||
// MigrationEntry re-exports extpoints.MigrationEntry.
|
||||
type MigrationEntry = extpoints.MigrationEntry
|
||||
|
||||
// TaskExtension re-exports extpoints.TaskExtension.
|
||||
type TaskExtension = extpoints.TaskExtension
|
||||
|
||||
// TaskDefinition re-exports extpoints.TaskDefinition.
|
||||
type TaskDefinition = extpoints.TaskDefinition
|
||||
|
||||
// TaskOption re-exports extpoints.TaskOption.
|
||||
type TaskOption = extpoints.TaskOption
|
||||
|
||||
// ScheduleExtension re-exports extpoints.ScheduleExtension.
|
||||
type ScheduleExtension = extpoints.ScheduleExtension
|
||||
|
||||
// ScheduleDefinition re-exports extpoints.ScheduleDefinition.
|
||||
type ScheduleDefinition = extpoints.ScheduleDefinition
|
||||
|
||||
// ScheduleOption re-exports extpoints.ScheduleOption.
|
||||
type ScheduleOption = extpoints.ScheduleOption
|
||||
|
||||
// SettingExtension re-exports extpoints.SettingExtension.
|
||||
type SettingExtension = extpoints.SettingExtension
|
||||
|
||||
// SettingSchema re-exports extpoints.SettingSchema.
|
||||
type SettingSchema = extpoints.SettingSchema
|
||||
|
||||
Reference in New Issue
Block a user