Files
ai-agent-scaffold-go/internal/domain/shared/tree/router.go

20 lines
395 B
Go
Raw Normal View History

2026-05-30 23:16:49 +08:00
package tree
import "context"
type Handler[C any, D any, R any] interface {
Apply(ctx context.Context, command C, dynamic D) (R, error)
}
func Route[C any, D any, R any](ctx context.Context, next Handler[C, D, R], command C, dynamic D) (R, error) {
if next == nil {
return zero[R](), nil
}
return next.Apply(ctx, command, dynamic)
}
func zero[T any]() T {
var value T
return value
}