lynx

package module
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

README ยถ

Lynx Logo

Go-Lynx

The Plug-and-Play Go Microservices Framework

GoDoc codeCov Go Report Card License Discord Release Stars

๐Ÿ“Š Event System

Lynx provides a unified event system for inter-plugin communication:

Event Types

Lynx supports various event types:

// Add event listener
listener := &MyEventListener{}
runtime.AddListener(listener, nil)

// Add plugin-specific listener
runtime.AddPluginListener("my-plugin", listener, nil)

// Emit events
runtime.EmitPluginEvent("my-plugin", "started", map[string]any{
    "timestamp": time.Now().Unix(),
})

Event Filtering

Lynx supports event filtering to process only relevant events:

event_filters:
  - type: "started"
    plugin: "http"
  - type: "stopped"
    plugin: "grpc"

๐Ÿ“ˆ Monitoring and Observability

Lynx provides comprehensive monitoring and observability features:

Metrics

Lynx integrates with Prometheus for metrics collection:

metrics:
  enabled: true
  endpoint: "/metrics"
  namespace: "lynx"
  subsystem: "http"
  labels:
    - "service"
    - "instance"

Tracing

Lynx integrates with OpenTelemetry for distributed tracing:

tracing:
  enabled: true
  provider: "otlp"
  endpoint: "localhost:4317"
  service_name: "demo"
  sample_rate: 0.1

Logging

Lynx provides structured logging with Zap:

logging:
  level: "info"
  format: "json"
  output: "stdout"
  caller: true
  stacktrace: true

Health Checks

Lynx includes health checks for monitoring service health:

health:
  enabled: true
  endpoint: "/health"
  checks:
    - name: "database"
      timeout: 5s
    - name: "redis"
      timeout: 2s

๐Ÿš€ Production-Ready Features

Lynx includes several production-ready features:

Graceful Shutdown

Lynx supports graceful shutdown to ensure all requests are processed before shutting down:

graceful_shutdown:
  timeout: 30s
  wait_for_ongoing_requests: true
  max_wait_time: 60s

Rate Limiting

Lynx includes rate limiting to prevent abuse:

rate_limit:
  enabled: true
  rate_per_second: 100
  burst_limit: 200

Retry Policies

Lynx supports retry policies for handling transient failures:

retry:
  enabled: true
  max_attempts: 3
  initial_interval: 100ms
  max_interval: 1s
  multiplier: 2.0

Dead Letter Queues

Lynx supports dead letter queues for handling failed messages:

dead_letter_queue:
  enabled: true
  max_retries: 3
  destination: "dlq-topic"

Translations: English | ็ฎ€ไฝ“ไธญๆ–‡

๐Ÿš€ What is Lynx?

Lynx is a revolutionary open-source microservices framework that transforms the way developers build distributed systems. Built on the robust foundations of Seata, Polaris, and Kratos, Lynx delivers a seamless plug-and-play experience that lets you focus on business logic while we handle the infrastructure complexity.

๐ŸŽฏ Why Choose Lynx?

  • โšก Zero Configuration: Get started in minutes with minimal setup
  • ๐Ÿ”Œ Plugin-Driven: Modular architecture with hot-pluggable components
  • ๐Ÿ›ก๏ธ Enterprise Ready: Production-grade reliability and security
  • ๐Ÿ“ˆ Scalable: Built for high-performance microservices
  • ๐Ÿ”„ Cloud Native: Designed for modern cloud environments

๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Lynx Application Layer                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚  โ”‚ LynxApp     โ”‚  โ”‚ Boot        โ”‚  โ”‚ Control     โ”‚           โ”‚
โ”‚  โ”‚             โ”‚  โ”‚             โ”‚  โ”‚ Plane       โ”‚           โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                                โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Plugin Management Layer                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚  โ”‚ Plugin      โ”‚  โ”‚ TypedPlugin โ”‚  โ”‚ Plugin      โ”‚           โ”‚
โ”‚  โ”‚ Manager     โ”‚  โ”‚ Manager     โ”‚  โ”‚ Factory     โ”‚           โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                                โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    Runtime Layer                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚  โ”‚ Runtime     โ”‚  โ”‚ TypedRuntimeโ”‚  โ”‚ Simple      โ”‚           โ”‚
โ”‚  โ”‚ Interface   โ”‚  โ”‚ Impl        โ”‚  โ”‚ Runtime     โ”‚           โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                                โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                Resource Management Layer                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚  โ”‚ Private     โ”‚  โ”‚ Shared      โ”‚  โ”‚ Resource    โ”‚           โ”‚
โ”‚  โ”‚ Resources   โ”‚  โ”‚ Resources   โ”‚  โ”‚ Info        โ”‚           โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Key Features

๐Ÿ” Service Discovery & Registration

  • Automatic Service Registration: Seamlessly register your services
  • Smart Service Discovery: Dynamic service discovery with health checks
  • Multi-Version Support: Deploy multiple service versions simultaneously
  • Load Balancing: Intelligent traffic distribution

๐Ÿ” Security & Communication

  • Encrypted Intranet Communication: End-to-end encryption for service communication
  • Authentication & Authorization: Built-in security mechanisms
  • TLS Support: Secure transport layer communication

๐Ÿšฆ Traffic Management

  • Rate Limiting: Prevent service overload with intelligent throttling
  • Circuit Breaker: Automatic fault tolerance and recovery
  • Traffic Routing: Intelligent routing with blue-green and canary deployments
  • Fallback Mechanisms: Graceful degradation during failures

๐Ÿ’พ Distributed Transactions

  • ACID Compliance: Ensure data consistency across services
  • Automatic Rollback: Handle transaction failures gracefully
  • Performance Optimized: Minimal overhead for distributed transactions

๐Ÿ”Œ Plugin Architecture

  • Hot-Pluggable: Add or remove features without code changes
  • Extensible: Easy integration of third-party tools
  • Modular Design: Clean separation of concerns

๐Ÿ› ๏ธ Built With

Lynx leverages battle-tested open-source technologies:

Component Technology Purpose
Service Discovery Polaris Service registration and discovery
Distributed Transactions Seata ACID transactions across services
Framework Core Kratos High-performance microservices framework
Language Go Fast, reliable, and concurrent

๐Ÿš€ Quick Start

1. Install Lynx CLI

go install github.com/go-lynx/lynx/cmd/lynx@latest

2. Create Your Project

# Create a single project
lynx new my-service

# Create multiple projects at once
lynx new service1 service2 service3

3. Write Your Code

package main

import (
    "github.com/go-lynx/lynx/app"
    "github.com/go-lynx/lynx/app/boot"
)

func main() {
    // That's it! Lynx handles everything else
    boot.LynxApplication(wireApp).Run()
}

4. Configure Your Services

# config.yml
lynx:
  polaris:
    namespace: "default"
    weight: 100
  http:
    addr: ":8080"
    timeout: "10s"
  grpc:
    addr: ":9090"
    timeout: "5s"

๐Ÿ” Security

Lynx provides comprehensive security features to protect your microservices:

TLS Configuration

Lynx supports TLS for secure communication between services:

tls:
  source_type: local_file  # Options: local_file, memory, etc.
  auth_type: mutual        # Options: no_client_cert, request_client_cert, require_any_client_cert, etc.
  min_version: TLS1.2      # Minimum TLS version
  cert_file: /path/to/cert.pem
  key_file: /path/to/key.pem
  ca_file: /path/to/ca.pem

Authentication

Lynx supports various authentication mechanisms:

  • TLS Mutual Authentication: Client and server authenticate each other using certificates
  • OAuth2: Support for OAuth2 authentication flows
  • API Keys: Simple API key authentication
  • JWT: JSON Web Token authentication

Authorization

Lynx provides flexible authorization mechanisms:

  • Role-Based Access Control (RBAC): Control access based on roles
  • Attribute-Based Access Control (ABAC): Fine-grained access control based on attributes
  • Policy Enforcement: Enforce access policies at the service level

โš ๏ธ Error Handling

Lynx provides a comprehensive error handling framework:

Error Types

Lynx defines common error types for consistent error handling:

// Common errors
var (
    ErrCacheMiss  = errors.New("cache: key not found")
    ErrCacheSet   = errors.New("cache: failed to set value")
    ErrInvalidTTL = errors.New("cache: invalid TTL")
)

Error Recovery

Lynx includes an error recovery manager for handling and recovering from errors:

// ErrorRecoveryManager provides centralized error handling and recovery
type ErrorRecoveryManager struct {
    // Error tracking
    errorCounts     map[string]int64
    errorHistory    []ErrorRecord
    recoveryHistory []RecoveryRecord

    // Circuit breakers for different error types
    circuitBreakers map[string]*CircuitBreaker

    // Recovery strategies
    recoveryStrategies map[string]RecoveryStrategy
    
    // ... other fields
}

Circuit Breakers

Lynx includes circuit breakers to prevent cascading failures:

circuit_breaker:
  enabled: true
  threshold: 5        # Number of errors before opening the circuit
  timeout: 30s        # Time to keep the circuit open
  half_open_timeout: 5s  # Time to wait in half-open state

๐Ÿ“Š Performance & Scalability

  • โšก High Performance: Optimized for low latency and high throughput
  • ๐Ÿ“ˆ Horizontal Scaling: Easy scaling across multiple instances
  • ๐Ÿ”„ Zero Downtime: Rolling updates and graceful shutdowns
  • ๐Ÿ“Š Monitoring: Built-in metrics and observability

๐Ÿงฐ CLI Logging & I18n

Lynx CLI provides a unified, level-based logger and internationalized messages.

Logging

  • Env vars
    • LYNX_LOG_LEVEL: one of error|warn|info|debug (default: info)
    • LYNX_QUIET: suppress non-error outputs when set to 1/true
    • LYNX_VERBOSE: enable verbose mode when set to 1/true
  • Flags (override env for current command)
    • --log-level <level>
    • --quiet / -q
    • --verbose / -v

Examples:

# quiet mode
LYNX_QUIET=1 lynx new demo

# debug logs for one run
lynx --log-level=debug new demo

Internationalization (i18n)

  • Env var: LYNX_LANG with zh or en.
  • All user-facing messages respect this setting.

Examples:

LYNX_LANG=en lynx new demo
LYNX_LANG=zh lynx new demo

๐Ÿงญ CLI Commands

๐Ÿ“‹ lynx new - Create New Projects

Common flags for lynx new:

  • --repo-url, -r: layout repository URL (env: LYNX_LAYOUT_REPO)
  • --branch, -b: branch name for layout repo
  • --ref: commit/tag/branch to checkout; takes precedence over --branch
  • --module, -m: go module path for the new project (e.g. github.com/acme/foo)
  • --force, -f: overwrite existing directory without prompt
  • --post-tidy: run go mod tidy after generation
  • --timeout, -t: creation timeout (e.g. 60s)
  • --concurrency, -c: max concurrent project creations

Examples:

# use a specific tag
lynx new demo --ref v1.2.3

# set module and run mod tidy automatically
lynx new demo -m github.com/acme/demo --post-tidy

# create multiple projects with concurrency 4
lynx new svc-a svc-b svc-c svc-d -c 4

๐Ÿ” lynx doctor - Diagnose Environment & Project Health

The lynx doctor command performs comprehensive health checks on your development environment and Lynx project.

What It Checks

Environment Checks:

  • โœ… Go installation and version (minimum Go 1.20+)
  • โœ… Go environment variables (GOPATH, GO111MODULE, GOPROXY)
  • โœ… Git repository status and uncommitted changes

Tool Checks:

  • โœ… Protocol Buffers compiler (protoc) installation
  • โœ… Wire dependency injection tool availability
  • โœ… Required development tools for Lynx projects

Project Structure:

  • โœ… Validates expected directory structure (app/, boot/, plugins/, etc.)
  • โœ… Checks go.mod file existence and validity
  • โœ… Verifies Makefile and expected targets

Configuration:

  • โœ… Scans and validates YAML/YML configuration files
  • โœ… Checks configuration syntax and structure
Output Formats
  • Text (default): Human-readable with colors and icons
  • JSON: Machine-readable for CI/CD integration
  • Markdown: Documentation-friendly format
Command Options
# Run all diagnostic checks
lynx doctor

# Output in JSON format (for CI/CD)
lynx doctor --format json

# Output in Markdown format
lynx doctor --format markdown > health-report.md

# Check specific category only
lynx doctor --category env      # Environment only
lynx doctor --category tools    # Tools only
lynx doctor --category project  # Project structure only
lynx doctor --category config   # Configuration only

# Auto-fix issues when possible
lynx doctor --fix

# Show detailed diagnostic information
lynx doctor --verbose
Auto-Fix Capabilities

The --fix flag can automatically resolve:

  • Missing development tools (installs via make init or go install)
  • go.mod issues (runs go mod tidy)
  • Other fixable configuration problems
Health Status Indicators
  • ๐Ÿ’š Healthy: All checks passed
  • ๐Ÿ’› Degraded: Some warnings detected but functional
  • ๐Ÿ”ด Critical: Errors found that need attention
Example Output
๐Ÿ” Lynx Doctor - Diagnostic Report
==================================================

๐Ÿ“Š System Information:
  โ€ข OS/Arch: darwin/arm64
  โ€ข Go Version: go1.24.4
  โ€ข Lynx Version: v2.0.0

๐Ÿ”Ž Diagnostic Checks:
--------------------------------------------------
โœ… Go Version: Go 1.24 installed
โœ… Project Structure: All expected directories found
โš ๏ธ Wire Dependency Injection: Not installed
   ๐Ÿ’ก Fix available (use --fix to apply)

๐Ÿ“ˆ Summary:
  Total Checks: 9
  โœ… Passed: 7
  โš ๏ธ Warnings: 2

๐Ÿ’› Overall Health: Degraded

๐Ÿš€ lynx run - Quick Development Server

The lynx run command provides a convenient way to build and run your Lynx project with optional hot reload for rapid development.

Features
  • Automatic Build & Run: Compiles and executes your project in one command
  • Hot Reload: Automatically rebuilds and restarts on file changes (with --watch flag)
  • Process Management: Graceful shutdown and restart handling
  • Smart Detection: Automatically finds main package in project structure
  • Environment Control: Pass custom environment variables and arguments
Command Options
lynx run [path] [flags]

Flags:

  • --watch, -w: Enable hot reload (watch for file changes)
  • --build-args: Additional arguments for go build
  • --run-args: Arguments to pass to the running application
  • --verbose, -v: Enable verbose output
  • --env, -e: Environment variables (KEY=VALUE)
  • --port, -p: Override the application port
  • --skip-build: Skip build and run existing binary
Example Usage
# Run project in current directory
lynx run

# Run with hot reload (auto-restart on file changes)
lynx run --watch

# Run specific project directory
lynx run ./my-service

# Pass custom build flags
lynx run --build-args="-ldflags=-s -w"

# Pass runtime configuration
lynx run --run-args="--config=./configs"

# Set environment variables
lynx run -e PORT=8080 -e ENV=development

# Run existing binary without rebuild
lynx run --skip-build
Hot Reload Details

When using --watch mode, the following files trigger rebuilds:

  • Go source files (.go)
  • Go module files (go.mod, go.sum)
  • Configuration files (.yaml, .yml, .json, .toml)
  • Environment files (.env)
  • Protocol buffer files (.proto)

Ignored paths:

  • .git, .idea, vendor, node_modules
  • Build directories (bin, dist, tmp)
  • Test files (*_test.go)

๐ŸŽฏ Use Cases

๐Ÿข Enterprise Applications

  • Microservices Migration: Legacy system modernization
  • Cloud-Native Applications: Kubernetes and container-native deployments
  • High-Traffic Services: E-commerce and financial applications

๐Ÿš€ Startups & Scale-ups

  • Rapid Development: Quick time-to-market with minimal setup
  • Cost Optimization: Efficient resource utilization
  • Team Productivity: Focus on business logic, not infrastructure

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ› Report Bugs

Found a bug? Please open an issue.

๐Ÿ’ก Suggest Features

Have an idea? We'd love to hear it! Start a discussion.


๐Ÿ“š Documentation


๐Ÿ“„ License

This project is licensed under the Apache License 2.0.


๐Ÿค Contributing

We welcome contributions to Lynx! Here's how you can help:

  1. Report Issues: Report bugs or suggest features by opening an issue.
  2. Submit Pull Requests: Submit PRs for bug fixes or new features.
  3. Improve Documentation: Help improve documentation or add examples.
  4. Spread the Word: Star the repository and share it with others.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

๐Ÿ“š Documentation

For more detailed documentation, please visit:

๐Ÿ“œ License

Lynx is licensed under the Apache License 2.0. See LICENSE for the full license text.

โญ Star History

Star History Chart


Join thousands of developers building the future with Lynx! ๐Ÿš€

๐Ÿ’ฌ Discord โ€ข ๐ŸŒ Website โ€ข ๐Ÿ› Issues โ€ข ๐Ÿ’ก Discussions

Documentation ยถ

Overview ยถ

Package lynx provides the core application framework for building microservices.

This file (app.go) contains the LynxApp structure and main API entry points.

Package lynx provides the core application framework for building microservices.

This file (certificate.go) contains TLS certificate management:

  • CertificateProvider: Interface for accessing TLS certificates
  • Certificate and private key retrieval
  • Root CA certificate for trust chain verification

Package lynx provides the core application framework for building microservices.

This file (controlplane.go) contains the control plane interfaces and implementation:

  • ControlPlane: Main interface for service management
  • RateLimiter: HTTP and gRPC rate limiting
  • ServiceRegistry: Service registration and discovery
  • RouteManager: Service routing and node filtering
  • ConfigManager: Configuration source management
  • DefaultControlPlane: Basic implementation for local development

Package lynx provides the core application framework for building microservices.

Lynx is a plug-and-play Go microservices framework built on top of Kratos, providing a unified runtime environment for plugin-based application development.

Architecture ยถ

The framework is organized around the following core concepts:

  • LynxApp: The main application instance managing lifecycle and configuration
  • Plugin Manager: Handles plugin registration, dependency resolution, and lifecycle
  • Runtime: Provides resource sharing, event handling, and configuration access
  • Control Plane: Manages service discovery, rate limiting, and routing

File Organization ยถ

The root package contains the following files:

  • app.go: LynxApp core structure, initialization, and main API
  • manager.go: Plugin manager interfaces and implementation
  • lifecycle.go: Plugin lifecycle operations (init/start/stop)
  • ops.go: Plugin loading and unloading operations
  • topology.go: Plugin dependency resolution and ordering
  • runtime.go: Runtime plugin providing resource and event management
  • controlplane.go: Control plane interfaces for service management
  • certificate.go: TLS certificate provider interface
  • prepare.go: Plugin preparation and bootstrapping from configuration
  • recovery.go: Error recovery and resilience mechanisms

Quick Start ยถ

Basic usage of the Lynx framework:

package main

import (
    "github.com/go-kratos/kratos/v2/config"
    "github.com/go-kratos/kratos/v2/config/file"
    "github.com/go-lynx/lynx"
    "github.com/go-lynx/lynx/boot"
)

func main() {
    // Load configuration
    cfg := config.New(config.WithSource(file.NewSource("config.yaml")))
    cfg.Load()

    // Create application with plugins
    app, err := lynx.NewApp(cfg)
    if err != nil {
        panic(err)
    }
    defer app.Close()

    // Load and start plugins
    if err := app.GetPluginManager().LoadPlugins(cfg); err != nil {
        panic(err)
    }

    // Run application using boot package
    boot.Run(app)
}

Plugin Development ยถ

To create a custom plugin, implement the plugins.Plugin interface:

type MyPlugin struct {
    *plugins.BasePlugin
}

func (p *MyPlugin) Name() string { return "my-plugin" }
func (p *MyPlugin) ID() string   { return "my-plugin-v1" }

func (p *MyPlugin) Initialize(plugin plugins.Plugin, rt plugins.Runtime) error {
    // Initialization logic
    return nil
}

func (p *MyPlugin) Start(plugin plugins.Plugin) error {
    // Startup logic
    return nil
}

func (p *MyPlugin) Stop(plugin plugins.Plugin) error {
    // Shutdown logic
    return nil
}

Configuration ยถ

The framework uses YAML configuration files. See conf/boot-example.yml for a complete configuration reference.

For More Information ยถ

Visit the official documentation at https://go-lynx.cn/docs

Package lynx provides the core application framework for building microservices.

This file (lifecycle.go) contains plugin lifecycle operations including:

  • Plugin initialization with timeout and error recovery
  • Plugin startup with parallel execution and rollback
  • Plugin shutdown with graceful termination
  • Context-aware lifecycle support for cancellation

Package lynx provides the core application framework for building microservices.

This file (manager.go) contains the plugin manager interfaces and implementation. The plugin manager handles plugin registration, lookup, and lifecycle coordination.

Package lynx provides the core application framework for building microservices.

This file (ops.go) contains plugin manager operations including:

  • LoadPlugins: Load and start all configured plugins
  • UnloadPlugins: Gracefully stop and unload all plugins
  • LoadPluginsByName: Load specific plugins by name
  • UnloadPluginsByName: Unload specific plugins by name
  • StopPlugin: Stop a single plugin
  • Resource management and monitoring utilities

Package lynx provides the core application framework for building microservices.

This file (prepare.go) contains plugin preparation and bootstrapping:

  • PreparePlug: Bootstrap plugin loading from configuration
  • Plugin factory integration for automatic plugin creation
  • Configuration-driven plugin registration

Package lynx provides the core application framework for building microservices.

This file (recovery.go) contains error recovery and resilience mechanisms:

  • CircuitBreaker: Prevents cascading failures
  • ErrorRecoveryManager: Manages error detection and recovery
  • Health monitoring and automatic recovery strategies
  • Panic recovery with detailed diagnostics

Package lynx provides the core application framework for building microservices.

This file (runtime.go) contains the runtime plugin implementation:

  • TypedRuntimePlugin: Core runtime for resource and event management
  • Resource registration and retrieval (shared and private)
  • Event emission and listener management
  • Configuration access and updates
  • Plugin context management

Package lynx provides the core application framework for building microservices.

This file (topology.go) contains plugin dependency resolution utilities:

  • TopologicalSort: Sort plugins based on dependencies
  • Dependency graph construction and validation
  • Level calculation for parallel plugin loading

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func GetHost ยถ

func GetHost() string

GetHost retrieves the hostname of the current application instance. Returns an empty string if the application is not initialized.

func GetName ยถ

func GetName() string

GetName retrieves the application name. Returns an empty string if the application is not initialized.

func GetServiceDiscovery ยถ

func GetServiceDiscovery() (registry.Discovery, error)

GetServiceDiscovery returns a new service discovery instance

func GetServiceRegistry ยถ

func GetServiceRegistry() (registry.Registrar, error)

GetServiceRegistry returns a new service registry instance

func GetTypedPlugin ยถ

func GetTypedPlugin[T plugins.Plugin](name string) (T, error)

GetTypedPlugin globally retrieves a type-safe plugin instance

func GetTypedPluginFromManager ยถ

func GetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) (T, error)

GetTypedPluginFromManager gets a typed plugin from any TypedPluginManager.

func GetTypedResource ยถ

func GetTypedResource[T any](r *TypedRuntimePlugin, name string) (T, error)

GetTypedResource retrieves a type-safe resource (standalone helper)

func GetVersion ยถ

func GetVersion() string

GetVersion retrieves the application version. Returns an empty string if the application is not initialized.

func ListPluginNames ยถ

func ListPluginNames(m TypedPluginManager) []string

ListPluginNames Public helpers for any TypedPluginManager.

func MustGetTypedPluginFromManager ยถ

func MustGetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) T

MustGetTypedPluginFromManager gets typed plugin or panics.

func RegisterTypedResource ยถ

func RegisterTypedResource[T any](r *TypedRuntimePlugin, name string, resource T) error

RegisterTypedResource registers a type-safe resource (standalone helper)

Types ยถ

type CertificateProvider ยถ

type CertificateProvider interface {
	// GetCertificate returns the TLS/SSL certificate as a byte slice.
	// The certificate should be in PEM format.
	GetCertificate() []byte

	// GetPrivateKey returns the private key associated with the certificate as a byte slice.
	// The private key should be in PEM format.
	GetPrivateKey() []byte

	// GetRootCACertificate returns the root CA certificate as a byte slice.
	// The root CA certificate should be in PEM format.
	// This certificate is used to verify the trust chain.
	GetRootCACertificate() []byte
}

CertificateProvider defines an interface for managing TLS/SSL certificates. It provides methods to access the certificate, private key, and root Certificate Authority (CA) certificate required for secure communication.

type CircuitBreaker ยถ

type CircuitBreaker struct {
	// contains filtered or unexported fields
}

CircuitBreaker provides error handling and recovery

func (*CircuitBreaker) CanExecute ยถ

func (cb *CircuitBreaker) CanExecute() bool

CanExecute checks if the circuit breaker allows execution

func (*CircuitBreaker) GetState ยถ

func (cb *CircuitBreaker) GetState() CircuitState

GetState returns the current circuit breaker state

func (*CircuitBreaker) RecordResult ยถ

func (cb *CircuitBreaker) RecordResult(err error)

RecordResult records the result of an operation

type CircuitState ยถ

type CircuitState int

CircuitState represents the state of circuit breaker

const (
	CircuitStateClosed CircuitState = iota
	CircuitStateOpen
	CircuitStateHalfOpen
)

type ConfigManager ยถ

type ConfigManager interface {
	// GetConfig retrieves configuration from a source using the specified file and group
	GetConfig(fileName string, group string) (config.Source, error)
}

ConfigManager provides configuration management functionality

type ControlPlane ยถ

type ControlPlane interface {
	// SystemCore provides basic application information.
	SystemCore
	// RateLimiter provides rate limiting functionality for HTTP and gRPC services.
	RateLimiter
	// ServiceRegistry provides service registration and discovery functionality.
	ServiceRegistry
	// RouteManager provides service routing functionality.
	RouteManager
	// ConfigManager provides configuration management functionality.
	ConfigManager
}

ControlPlane defines the interface for managing core application services including rate limiting, service discovery, routing, and configuration

type DefaultControlPlane ยถ

type DefaultControlPlane struct {
}

DefaultControlPlane provides a basic implementation of the ControlPlane interface for local development and testing purposes

func (*DefaultControlPlane) GRPCRateLimit ยถ

func (c *DefaultControlPlane) GRPCRateLimit() middleware.Middleware

GRPCRateLimit implements the RateLimiter interface for gRPC rate limiting

func (*DefaultControlPlane) GetConfig ยถ

func (c *DefaultControlPlane) GetConfig(fileName string, group string) (config.Source, error)

GetConfig implements the ConfigManager interface for configuration management

func (*DefaultControlPlane) GetNamespace ยถ

func (c *DefaultControlPlane) GetNamespace() string

GetNamespace implements the SystemCore interface for namespace management

func (*DefaultControlPlane) HTTPRateLimit ยถ

func (c *DefaultControlPlane) HTTPRateLimit() middleware.Middleware

HTTPRateLimit implements the RateLimiter interface for HTTP rate limiting

func (*DefaultControlPlane) NewNodeRouter ยถ

func (c *DefaultControlPlane) NewNodeRouter(serviceName string) selector.NodeFilter

NewNodeRouter implements the RouteManager interface for service routing

func (*DefaultControlPlane) NewServiceDiscovery ยถ

func (c *DefaultControlPlane) NewServiceDiscovery() registry.Discovery

NewServiceDiscovery implements the ServiceRegistry interface for service discovery

func (*DefaultControlPlane) NewServiceRegistry ยถ

func (c *DefaultControlPlane) NewServiceRegistry() registry.Registrar

NewServiceRegistry implements the ServiceRegistry interface for service registration

type DefaultPluginManager ยถ

type DefaultPluginManager[T plugins.Plugin] struct {
	// contains filtered or unexported fields
}

DefaultPluginManager is the generic plugin manager implementation.

func NewPluginManager ยถ

func NewPluginManager[T plugins.Plugin](pluginList ...T) *DefaultPluginManager[T]

NewPluginManager creates a generic plugin manager.

func (*DefaultPluginManager[T]) ClearUnloadFailures ยถ

func (m *DefaultPluginManager[T]) ClearUnloadFailures()

ClearUnloadFailures clears all recorded unload failures

func (*DefaultPluginManager[T]) GetPlugin ยถ

func (m *DefaultPluginManager[T]) GetPlugin(name string) plugins.Plugin

GetPlugin gets a plugin by Name().

func (*DefaultPluginManager[T]) GetResourceStats ยถ

func (m *DefaultPluginManager[T]) GetResourceStats() map[string]any

GetResourceStats Resource helpers.

func (*DefaultPluginManager[T]) GetRuntime ยถ

func (m *DefaultPluginManager[T]) GetRuntime() plugins.Runtime

GetRuntime returns the shared runtime.

func (*DefaultPluginManager[T]) GetUnloadFailures ยถ

func (m *DefaultPluginManager[T]) GetUnloadFailures() []UnloadFailureRecord

GetUnloadFailures returns all recorded plugin unload failures

func (*DefaultPluginManager[T]) ListResources ยถ

func (m *DefaultPluginManager[T]) ListResources() []*plugins.ResourceInfo

func (*DefaultPluginManager[T]) LoadPlugins ยถ

func (m *DefaultPluginManager[T]) LoadPlugins(conf config.Config) error

LoadPlugins loads and starts all plugins.

func (*DefaultPluginManager[T]) LoadPluginsByName ยถ

func (m *DefaultPluginManager[T]) LoadPluginsByName(conf config.Config, pluginNames []string) error

LoadPluginsByName loads a subset of plugins by Name().

func (*DefaultPluginManager[T]) PreparePlug ยถ

func (m *DefaultPluginManager[T]) PreparePlug(config config.Config) ([]plugins.Plugin, error)

PreparePlug bootstraps plugin loading via remote or local configuration files. It initializes and registers plugins based on configuration. If a single plugin fails, it logs the error and skips that plugin, attempting to return other successful items. Returns a list of successfully prepared plugins (possibly empty) and an error only for global failures.

func (*DefaultPluginManager[T]) SetConfig ยถ

func (m *DefaultPluginManager[T]) SetConfig(conf config.Config)

SetConfig sets global config.

func (*DefaultPluginManager[T]) StopPlugin ยถ

func (m *DefaultPluginManager[T]) StopPlugin(pluginName string) error

StopPlugin stops a single plugin by Name().

func (*DefaultPluginManager[T]) TopologicalSort ยถ

func (m *DefaultPluginManager[T]) TopologicalSort(plugs []plugins.Plugin) ([]PluginWithLevel, error)

TopologicalSort sorts a subset of plugins based on required dependencies and calculates an integer level for each plugin. It performs a topological sort on the plugin dependency graph and assigns each plugin a level based on the maximum depth of its dependencies.

Dependency timing: GetDependencies() is called on each plugin before any plugin is initialized. Required dependencies that affect load order must therefore be declared in the plugin constructor (or before this sort runs), not only in InitializeResources. See plugins package README "Dependency declaration timing".

Parameters:

  • plugs: slice of plugins to sort and calculate levels for

Returns:

  • []PluginWithLevel: sorted plugins with their dependency levels
  • error: if there's a circular dependency or other resolution error

func (*DefaultPluginManager[T]) UnloadOrder ยถ added in v1.5.3

func (m *DefaultPluginManager[T]) UnloadOrder(plugs []plugins.Plugin) []plugins.Plugin

UnloadOrder returns a best-effort unload order (dependents first, then dependencies). Only considers required dependencies that exist in plugs; ignores missing deps. Used when TopologicalSort fails so unload order is still dependency-aware. Builds load-order graph (dep -> dependent), runs Kahn; unload order = reverse(load order).

func (*DefaultPluginManager[T]) UnloadPlugins ยถ

func (m *DefaultPluginManager[T]) UnloadPlugins()

UnloadPlugins stops and unloads all plugins with overall timeout protection. Optimized for stability: adds total timeout, parallel unloading, and better error handling.

func (*DefaultPluginManager[T]) UnloadPluginsByName ยถ

func (m *DefaultPluginManager[T]) UnloadPluginsByName(names []string)

UnloadPluginsByName unloads a subset of plugins by Name().

type DefaultRecoveryStrategy ยถ

type DefaultRecoveryStrategy struct {
	// contains filtered or unexported fields
}

DefaultRecoveryStrategy implements a basic recovery strategy

func NewDefaultRecoveryStrategy ยถ

func NewDefaultRecoveryStrategy(name string, timeout time.Duration) *DefaultRecoveryStrategy

NewDefaultRecoveryStrategy creates a new default recovery strategy

func (*DefaultRecoveryStrategy) CanRecover ยถ

func (s *DefaultRecoveryStrategy) CanRecover(errorType string, severity ErrorSeverity) bool

CanRecover checks if this strategy can recover from the error

func (*DefaultRecoveryStrategy) GetTimeout ยถ

func (s *DefaultRecoveryStrategy) GetTimeout() time.Duration

GetTimeout returns the recovery timeout

func (*DefaultRecoveryStrategy) Name ยถ

func (s *DefaultRecoveryStrategy) Name() string

Name returns the strategy name

func (*DefaultRecoveryStrategy) Recover ยถ

func (s *DefaultRecoveryStrategy) Recover(ctx context.Context, record ErrorRecord) (bool, error)

Recover attempts to recover from the error

type ErrorCategory ยถ

type ErrorCategory string

ErrorCategory represents error categories for better classification

const (
	ErrorCategoryNetwork    ErrorCategory = "network"
	ErrorCategoryDatabase   ErrorCategory = "database"
	ErrorCategoryConfig     ErrorCategory = "configuration"
	ErrorCategoryPlugin     ErrorCategory = "plugin"
	ErrorCategoryResource   ErrorCategory = "resource"
	ErrorCategorySecurity   ErrorCategory = "security"
	ErrorCategoryTimeout    ErrorCategory = "timeout"
	ErrorCategoryValidation ErrorCategory = "validation"
	ErrorCategorySystem     ErrorCategory = "system"
)

type ErrorRecord ยถ

type ErrorRecord struct {
	Timestamp    time.Time
	ErrorType    string
	Category     ErrorCategory
	Message      string
	Component    string
	Severity     ErrorSeverity
	Context      map[string]interface{}
	Recovered    bool
	RecoveryTime *time.Time
	// Additional fields
	StackTrace  string
	UserID      string
	RequestID   string
	Environment string
	Version     string
}

ErrorRecord represents a recorded error with enhanced context

type ErrorRecoveryManager ยถ

type ErrorRecoveryManager struct {
	// contains filtered or unexported fields
}

ErrorRecoveryManager provides centralized error handling and recovery

func NewErrorRecoveryManager ยถ

func NewErrorRecoveryManager(metrics *metrics.ProductionMetrics) *ErrorRecoveryManager

NewErrorRecoveryManager creates a new error recovery manager

func (*ErrorRecoveryManager) ClearHistory ยถ

func (erm *ErrorRecoveryManager) ClearHistory()

ClearHistory clears error and recovery history

func (*ErrorRecoveryManager) GetErrorHistory ยถ

func (erm *ErrorRecoveryManager) GetErrorHistory() []ErrorRecord

GetErrorHistory returns error history

func (*ErrorRecoveryManager) GetErrorStats ยถ

func (erm *ErrorRecoveryManager) GetErrorStats() map[string]interface{}

GetErrorStats returns error statistics

func (*ErrorRecoveryManager) GetHealthReport ยถ

func (erm *ErrorRecoveryManager) GetHealthReport() map[string]interface{}

GetHealthReport returns a detailed health report

func (*ErrorRecoveryManager) GetRecoveryHistory ยถ

func (erm *ErrorRecoveryManager) GetRecoveryHistory() []RecoveryRecord

GetRecoveryHistory returns recovery history

func (*ErrorRecoveryManager) IsHealthy ยถ

func (erm *ErrorRecoveryManager) IsHealthy() bool

IsHealthy returns the health status of the error recovery manager

func (*ErrorRecoveryManager) RecordError ยถ

func (erm *ErrorRecoveryManager) RecordError(errorType string, category ErrorCategory, message, component string, severity ErrorSeverity, context map[string]interface{})

RecordError records an error with enhanced context and classification

func (*ErrorRecoveryManager) RegisterRecoveryStrategy ยถ

func (erm *ErrorRecoveryManager) RegisterRecoveryStrategy(errorType string, strategy RecoveryStrategy)

RegisterRecoveryStrategy registers a recovery strategy

func (*ErrorRecoveryManager) Stop ยถ

func (erm *ErrorRecoveryManager) Stop()

Stop stops the error recovery manager

type ErrorSeverity ยถ

type ErrorSeverity int

ErrorSeverity represents error severity levels

const (
	ErrorSeverityLow ErrorSeverity = iota
	ErrorSeverityMedium
	ErrorSeverityHigh
	ErrorSeverityCritical
)

type LynxApp ยถ

type LynxApp struct {
	// contains filtered or unexported fields
}

LynxApp represents the main application instance. It serves as the central coordinator for all application components, managing configuration, logging, plugins, and the control plane.

func Lynx ยถ

func Lynx() *LynxApp

Lynx returns the global LynxApp instance. It ensures thread-safe access to the singleton instance.

func NewApp ยถ

func NewApp(cfg config.Config, plugins ...plugins.Plugin) (*LynxApp, error)

NewApp creates a new Lynx application instance with the provided configuration and plugins. It initializes the application with system hostname and bootstrap configuration. Uses sync.Once to ensure thread-safe singleton initialization.

Parameters:

  • cfg: Configuration instance
  • plugins: Optional list of plugins to initialize with

Returns:

  • *LynxApp: Initialized application instance
  • error: Any error that occurred during initialization

func (*LynxApp) Certificate ยถ

func (a *LynxApp) Certificate() CertificateProvider

Certificate returns the current application's certificate provider. Returns nil if no certificate provider has been set.

func (*LynxApp) ClearUnloadFailures ยถ

func (a *LynxApp) ClearUnloadFailures()

ClearUnloadFailures clears recorded unload failures

func (*LynxApp) Close ยถ

func (a *LynxApp) Close() error

Close gracefully shuts down the Lynx application

func (*LynxApp) GetControlPlane ยถ

func (a *LynxApp) GetControlPlane() ControlPlane

GetControlPlane returns the current control plane instance

func (*LynxApp) GetControlPlaneConfigSources ยถ

func (a *LynxApp) GetControlPlaneConfigSources() ([]config.Source, error)

GetControlPlaneConfigSources gets all configuration sources from the control plane This method supports loading multiple configuration files from remote sources

func (*LynxApp) GetGlobalConfig ยถ

func (a *LynxApp) GetGlobalConfig() config.Config

GetGlobalConfig returns the global configuration instance. Returns nil if the application is not initialized.

func (*LynxApp) GetPluginManager ยถ

func (a *LynxApp) GetPluginManager() TypedPluginManager

GetPluginManager returns the plugin manager instance. Returns nil if the application is not initialized.

func (*LynxApp) GetResourceStats ยถ

func (a *LynxApp) GetResourceStats() map[string]any

GetResourceStats returns resource statistics from the plugin manager

func (*LynxApp) GetTypedPluginManager ยถ

func (a *LynxApp) GetTypedPluginManager() TypedPluginManager

GetTypedPluginManager returns the typed plugin manager instance. Returns nil if the application is not initialized. This is an alias for GetPluginManager() for backward compatibility.

func (*LynxApp) GetUnloadFailures ยถ

func (a *LynxApp) GetUnloadFailures() []UnloadFailureRecord

GetUnloadFailures returns plugin unload failures for monitoring

func (*LynxApp) InitControlPlaneConfig ยถ

func (a *LynxApp) InitControlPlaneConfig() (config.Config, error)

InitControlPlaneConfig initializes the control plane configuration It loads the configuration from the specified source and sets up the global configuration

func (*LynxApp) SetCertificateProvider ยถ

func (a *LynxApp) SetCertificateProvider(provider CertificateProvider)

SetCertificateProvider configures the certificate provider for the application. The provider parameter must implement the CertificateProvider interface.

func (*LynxApp) SetControlPlane ยถ

func (a *LynxApp) SetControlPlane(plane ControlPlane) error

SetControlPlane sets the control plane instance for the application

func (*LynxApp) SetGlobalConfig ยถ

func (a *LynxApp) SetGlobalConfig(cfg config.Config) error

SetGlobalConfig updates the global configuration instance. It properly closes the existing configuration before updating.

func (*LynxApp) Shutdown ยถ

func (a *LynxApp) Shutdown() error

Shutdown is an alias for Close for backward compatibility

type MultiConfigControlPlane ยถ

type MultiConfigControlPlane interface {
	ControlPlane
	// GetConfigSources retrieves all configuration sources for multi-config loading
	GetConfigSources() ([]config.Source, error)
}

MultiConfigControlPlane extends ControlPlane to support multiple configuration sources

type PluginManager ยถ

type PluginManager interface {
	// Basic plugin management
	LoadPlugins(config.Config) error
	UnloadPlugins()
	LoadPluginsByName(config.Config, []string) error
	UnloadPluginsByName([]string)
	GetPlugin(name string) plugins.Plugin
	PreparePlug(config config.Config) ([]plugins.Plugin, error)

	// Runtime and config
	GetRuntime() plugins.Runtime
	SetConfig(config.Config)

	// Resource operations
	StopPlugin(pluginName string) error
	GetResourceStats() map[string]any
	ListResources() []*plugins.ResourceInfo

	// Monitoring operations
	GetUnloadFailures() []UnloadFailureRecord
	ClearUnloadFailures()
}

PluginManager defines plugin management interfaces. Note: TypedPluginManager is an alias for PluginManager and should be used in all public APIs.

type PluginWithLevel ยถ

type PluginWithLevel struct {
	plugins.Plugin
	// contains filtered or unexported fields
}

PluginWithLevel represents a plugin with its dependency level. The level indicates how deep in the dependency chain this plugin is, with 0 being plugins with no dependencies.

type RateLimiter ยถ

type RateLimiter interface {
	// HTTPRateLimit returns middleware for HTTP rate limiting
	HTTPRateLimit() middleware.Middleware
	// GRPCRateLimit returns middleware for gRPC rate limiting
	GRPCRateLimit() middleware.Middleware
}

RateLimiter provides rate limiting functionality for HTTP and gRPC services

type RecoveryRecord ยถ

type RecoveryRecord struct {
	Timestamp time.Time
	ErrorType string
	Component string
	Strategy  string
	Success   bool
	Duration  time.Duration
	Message   string
}

RecoveryRecord represents a recovery attempt

type RecoveryStrategy ยถ

type RecoveryStrategy interface {
	Name() string
	CanRecover(errorType string, severity ErrorSeverity) bool
	Recover(ctx context.Context, record ErrorRecord) (bool, error)
	GetTimeout() time.Duration
}

RecoveryStrategy defines a recovery strategy

type RouteManager ยถ

type RouteManager interface {
	// NewNodeRouter creates a new node filter for the specified service
	NewNodeRouter(serviceName string) selector.NodeFilter
}

RouteManager provides service routing functionality

type RuntimePlugin ยถ

type RuntimePlugin = TypedRuntimePlugin

RuntimePlugin backward-compatible alias of TypedRuntimePlugin

func NewRuntimePlugin ยถ

func NewRuntimePlugin() *RuntimePlugin

NewRuntimePlugin creates a runtime plugin (backward-compatible)

type ServiceRegistry ยถ

type ServiceRegistry interface {
	// NewServiceRegistry creates a new service registrar
	NewServiceRegistry() registry.Registrar
	// NewServiceDiscovery creates a new service discovery client
	NewServiceDiscovery() registry.Discovery
}

ServiceRegistry provides service registration and discovery functionality

type SystemCore ยถ

type SystemCore interface {
	// GetNamespace returns the current application control plane namespace
	GetNamespace() string
}

SystemCore provides basic application information

type TypedPluginManager ยถ

type TypedPluginManager = PluginManager

TypedPluginManager is an alias for PluginManager.

func NewTypedPluginManager ยถ

func NewTypedPluginManager(pluginList ...plugins.Plugin) TypedPluginManager

NewTypedPluginManager creates a plugin manager with plugins.Plugin as T.

type TypedRuntimePlugin ยถ

type TypedRuntimePlugin struct {
	// contains filtered or unexported fields
}

TypedRuntimePlugin generic runtime plugin

func NewTypedRuntimePlugin ยถ

func NewTypedRuntimePlugin() *TypedRuntimePlugin

NewTypedRuntimePlugin creates a new TypedRuntimePlugin instance with default settings.

func (*TypedRuntimePlugin) AddListener ยถ

func (r *TypedRuntimePlugin) AddListener(listener plugins.EventListener, filter *plugins.EventFilter)

AddListener registers a new event listener with optional filters. This method is kept for backward compatibility but delegates to the unified event bus.

func (*TypedRuntimePlugin) AddPluginListener ยถ

func (r *TypedRuntimePlugin) AddPluginListener(pluginName string, listener plugins.EventListener, filter *plugins.EventFilter)

AddPluginListener adds a listener for plugin-specific events

func (*TypedRuntimePlugin) CleanupResources ยถ

func (r *TypedRuntimePlugin) CleanupResources(pluginID string) error

CleanupResources cleans up resources for a specific plugin

func (*TypedRuntimePlugin) Close ยถ

func (r *TypedRuntimePlugin) Close()

Close stops the runtime (optional to call)

func (*TypedRuntimePlugin) EmitEvent ยถ

func (r *TypedRuntimePlugin) EmitEvent(event plugins.PluginEvent)

EmitEvent broadcasts a plugin event to the unified event bus. Event will be processed according to its priority and any active filters.

func (*TypedRuntimePlugin) EmitPluginEvent ยถ

func (r *TypedRuntimePlugin) EmitPluginEvent(pluginName string, eventType string, data map[string]any)

EmitPluginEvent emits a plugin-specific event

func (*TypedRuntimePlugin) GetConfig ยถ

func (r *TypedRuntimePlugin) GetConfig() config.Config

GetConfig returns the plugin configuration manager. Provides access to configuration values and updates. Thread-safe: uses sync.Once to ensure initialization happens only once. Fixed: Replaced double-checked locking with sync.Once for better thread safety.

func (*TypedRuntimePlugin) GetCurrentPluginContext ยถ

func (r *TypedRuntimePlugin) GetCurrentPluginContext() string

GetCurrentPluginContext gets the current plugin context

func (*TypedRuntimePlugin) GetEventHistory ยถ

func (r *TypedRuntimePlugin) GetEventHistory(filter plugins.EventFilter) []plugins.PluginEvent

GetEventHistory retrieves historical events based on filter criteria. This method is kept for backward compatibility but delegates to the unified event bus.

func (*TypedRuntimePlugin) GetEventStats ยถ

func (r *TypedRuntimePlugin) GetEventStats() map[string]any

GetEventStats gets event system statistics

func (*TypedRuntimePlugin) GetLogger ยถ

func (r *TypedRuntimePlugin) GetLogger() log.Logger

GetLogger returns the plugin logger instance. Provides structured logging capabilities.

func (*TypedRuntimePlugin) GetPluginEventHistory ยถ

func (r *TypedRuntimePlugin) GetPluginEventHistory(pluginName string, filter plugins.EventFilter) []plugins.PluginEvent

GetPluginEventHistory gets event history for a specific plugin

func (*TypedRuntimePlugin) GetPrivateResource ยถ

func (r *TypedRuntimePlugin) GetPrivateResource(name string) (any, error)

GetPrivateResource gets a private resource for the current plugin context

func (*TypedRuntimePlugin) GetResource ยถ

func (r *TypedRuntimePlugin) GetResource(name string) (any, error)

GetResource retrieves a shared plugin resource by name. Returns the resource and any error encountered.

func (*TypedRuntimePlugin) GetResourceInfo ยถ

func (r *TypedRuntimePlugin) GetResourceInfo(name string) (*plugins.ResourceInfo, error)

GetResourceInfo gets resource information

func (*TypedRuntimePlugin) GetResourceStats ยถ

func (r *TypedRuntimePlugin) GetResourceStats() map[string]any

GetResourceStats gets resource statistics

func (*TypedRuntimePlugin) GetSharedResource ยถ

func (r *TypedRuntimePlugin) GetSharedResource(name string) (any, error)

GetSharedResource gets a shared resource accessible by all plugins

func (*TypedRuntimePlugin) ListResources ยถ

func (r *TypedRuntimePlugin) ListResources() []*plugins.ResourceInfo

ListResources lists all resources

func (*TypedRuntimePlugin) RegisterPrivateResource ยถ

func (r *TypedRuntimePlugin) RegisterPrivateResource(name string, resource any) error

RegisterPrivateResource registers a private resource for the current plugin context

func (*TypedRuntimePlugin) RegisterResource ยถ

func (r *TypedRuntimePlugin) RegisterResource(name string, resource any) error

RegisterResource registers a resource to be shared with other plugins. Returns an error if registration fails.

func (*TypedRuntimePlugin) RegisterSharedResource ยถ

func (r *TypedRuntimePlugin) RegisterSharedResource(name string, resource any) error

RegisterSharedResource registers a shared resource accessible by all plugins

func (*TypedRuntimePlugin) RemoveListener ยถ

func (r *TypedRuntimePlugin) RemoveListener(listener plugins.EventListener)

RemoveListener unregisters an event listener. This method is kept for backward compatibility but delegates to the unified event bus.

func (*TypedRuntimePlugin) SetConfig ยถ

func (r *TypedRuntimePlugin) SetConfig(conf config.Config)

SetConfig sets the configuration

func (*TypedRuntimePlugin) SetEventDispatchMode ยถ

func (r *TypedRuntimePlugin) SetEventDispatchMode(mode string) error

SetEventDispatchMode sets the event dispatch mode

func (*TypedRuntimePlugin) SetEventTimeout ยถ

func (r *TypedRuntimePlugin) SetEventTimeout(timeout time.Duration)

SetEventTimeout sets the event processing timeout

func (*TypedRuntimePlugin) SetEventWorkerPoolSize ยถ

func (r *TypedRuntimePlugin) SetEventWorkerPoolSize(size int)

SetEventWorkerPoolSize sets the event worker pool size

func (*TypedRuntimePlugin) WithPluginContext ยถ

func (r *TypedRuntimePlugin) WithPluginContext(pluginName string) plugins.Runtime

WithPluginContext creates a runtime with plugin context

type UnloadFailureRecord ยถ

type UnloadFailureRecord struct {
	PluginName   string
	PluginID     string
	FailureTime  time.Time
	StopError    error
	CleanupError error
	RetryCount   int
}

UnloadFailureRecord tracks plugin unload failures for monitoring

Directories ยถ

Path Synopsis
cmd
lynx module
internal
adapters
Package adapters provides internal adapter implementations for the Lynx framework.
Package adapters provides internal adapter implementations for the Lynx framework.
config
Package config provides a minimal validation framework used by plugins and core.
Package config provides a minimal validation framework used by plugins and core.
resource
Package resource provides simple runtime resources used by other components.
Package resource provides simple runtime resources used by other components.
Package kratos provides integration with the Kratos framework
Package kratos provides integration with the Kratos framework
log
Package log provides a unified logging interface for the Lynx framework.
Package log provides a unified logging interface for the Lynx framework.
observability
pkg
config
Package config provides a minimal validation framework used by plugins and core.
Package config provides a minimal validation framework used by plugins and core.
factory
Package factory provides functionality for creating and managing plugins in the Lynx framework.
Package factory provides functionality for creating and managing plugins in the Lynx framework.
fsx
idx
ptr
Package plugins provides the core plugin system for the Lynx framework.
Package plugins provides the core plugin system for the Lynx framework.
db/mysql module
db/pgsql module
mq/kafka module
nosql/redis module
polaris module
seata module
service/grpc module
service/http module
sql/base module
sql/mysql module
sql/pgsql module
swagger module
tracer module
tls

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL