Documentation
¶
Overview ¶
Package core contains the core implementation of the business logic.
Package core contains the domain types and interfaces for the plugin server.
Index ¶
- Constants
- Variables
- type AuditEntry
- type AuditLog
- type Core
- type CoreService
- type GenerateCodeRequest
- type GenerateCodeResponse
- type Metrics
- type Plugin
- type PluginFilter
- type PluginInfo
- type Registry
- type WorkerPool
- func (p *WorkerPool) Get(ctx context.Context, pluginGroup, pluginName, pluginVersion string) (Plugin, error)
- func (p *WorkerPool) List(ctx context.Context, filter PluginFilter) ([]PluginInfo, error)
- func (p *WorkerPool) Shutdown(timeout time.Duration) int
- func (p *WorkerPool) Start(ctx context.Context)
- type WorkerPoolConfig
Constants ¶
const ( OperationGenerateCode = "GENERATE_CODE" OperationListPlugins = "LIST_PLUGINS" )
Audit operation types.
const ( AuditStatusSuccess = "success" AuditStatusError = "error" )
Audit statuses.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrInvalidPluginName = errors.New("invalid plugin name") ErrGenerationFailed = errors.New("code generation failed") ErrServerOverloaded = errors.New("server overloaded") ErrShuttingDown = errors.New("server shutting down") )
Errors.
Functions ¶
This section is empty.
Types ¶
type AuditEntry ¶ added in v0.7.0
type AuditEntry struct {
ID uuid.UUID
OperationType string
PluginName string
CallerAddress string
Status string
ErrorCode string
ErrorMessage string
DurationMs int64
Metadata map[string]any
CreatedAt time.Time
}
AuditEntry представляет одну запись аудит-журнала.
type AuditLog ¶ added in v0.7.0
type AuditLog interface {
// Save сохраняет аудит-запись в хранилище.
Save(ctx context.Context, entry AuditEntry) error
}
AuditLog определяет интерфейс для записи аудит-событий.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core defines the interface for interacting with the plugin server.
func (*Core) Generate ¶
func (c *Core) Generate(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeResponse, error)
Generate generates code by plugin.
func (*Core) ListPlugins ¶
func (c *Core) ListPlugins(ctx context.Context, filter PluginFilter) ([]PluginInfo, error)
ListPlugins retrieves a list of plugins matching the filter.
type CoreService ¶ added in v0.7.0
type CoreService interface {
Generate(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeResponse, error)
ListPlugins(ctx context.Context, filter PluginFilter) ([]PluginInfo, error)
}
CoreService defines the business logic interface used by the API layer.
type GenerateCodeRequest ¶
type GenerateCodeRequest struct {
// PluginName identifies the plugin to use for code generation.
// Format: "<language>:v<version>" (e.g., "go:v1.36.9", "python:v3.20.0").
PluginName string
// Payload contains the protobuf code generation request with source files and parameters.
Payload *pluginpb.CodeGeneratorRequest
}
GenerateCodeRequest represents an incoming request to generate code using a specific plugin.
type GenerateCodeResponse ¶
type GenerateCodeResponse struct {
// Payload contains the protobuf code generation response with generated files.
Payload *pluginpb.CodeGeneratorResponse
}
GenerateCodeResponse wraps the response from a code generation operation.
type Metrics ¶
type Metrics interface {
// GenerateCode records metrics for a code generation request.
// The pluginName parameter identifies which plugin was used (e.g., "grpc/go:v1.36.9").
GenerateCode(ctx context.Context, info PluginInfo) error
// ObserveGenerationDuration records the duration of a code generation attempt.
ObserveGenerationDuration(ctx context.Context, pluginName string, duration time.Duration)
// IncGenerationErrors increments the generation error counter with the given error type.
IncGenerationErrors(ctx context.Context, pluginName string, errorType string)
// IncGenerationRetries increments the generation retry counter.
IncGenerationRetries(ctx context.Context, pluginName string)
}
Metrics defines the interface for collecting metrics about core operations.
type Plugin ¶
type Plugin interface {
// Generate processes a code generation request and produces generated code.
// Takes a protobuf CodeGeneratorRequest and returns a CodeGeneratorResponse
// containing the generated files or an error if generation fails.
Generate(ctx context.Context, req *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorResponse, error)
// Info retrieves information about a plugin by its identifier.
Info(ctx context.Context) *PluginInfo
}
Plugin represents a code generator plugin that processes protobuf definitions.
type PluginFilter ¶
PluginFilter represents a filter for listing plugins.
type PluginInfo ¶
type PluginInfo struct {
ID uuid.UUID
Group string
Name string
Version string
Tags []string
CreatedAt time.Time
}
PluginInfo represents information about a plugin.
type Registry ¶
type Registry interface {
// Get retrieves a plugin by its identifier.
// The pluginName parameter specifies the plugin to retrieve (e.g., "protobuf/go:v1.36.9").
// Returns an error if the plugin is not found or cannot be loaded.
Get(ctx context.Context, pluginGroup, pluginName, pluginVersion string) (Plugin, error)
// List retrieves a list of plugins matching the filter.
List(ctx context.Context, filter PluginFilter) ([]PluginInfo, error)
}
Registry provides access to available plugins.
type WorkerPool ¶ added in v0.7.0
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool управляет пулом горутин для ограничения параллелизма Docker-выполнения. Реализует интерфейс Registry, оборачивая реальный Registry.
func NewWorkerPool ¶ added in v0.7.0
func NewWorkerPool(inner Registry, cfg WorkerPoolConfig, logger *slog.Logger, metrics Metrics, reg *prometheus.Registry, namespace string) *WorkerPool
NewWorkerPool создаёт WorkerPool с нормализованной конфигурацией.
func (*WorkerPool) Get ¶ added in v0.7.0
func (p *WorkerPool) Get(ctx context.Context, pluginGroup, pluginName, pluginVersion string) (Plugin, error)
Get создаёт задание и отправляет его в очередь с backpressure.
func (*WorkerPool) List ¶ added in v0.7.0
func (p *WorkerPool) List(ctx context.Context, filter PluginFilter) ([]PluginInfo, error)
List проксирует запрос напрямую во внутренний Registry без очереди.
func (*WorkerPool) Shutdown ¶ added in v0.7.0
func (p *WorkerPool) Shutdown(timeout time.Duration) int
Shutdown закрывает канал заданий и ожидает завершения воркеров. Возвращает количество потерянных заданий.
func (*WorkerPool) Start ¶ added in v0.7.0
func (p *WorkerPool) Start(ctx context.Context)
Start запускает N горутин-воркеров.