GoWindGoWind
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
  • Introduction

    • GoWind Framework
    • Framework Architecture
  • go-wind Core

    • go-wind Core Framework
    • App Lifecycle Management
    • Context Propagation
    • Transport Abstraction
    • Log Facade Interface
  • go-wind-plugins

    • go-wind-plugins Plugin Overview
    • Plugin Configuration System
    • Plugin Registration Mechanism (SPI)
    • Logging Adapter Plugins
    • Transport Protocol Plugins
    • Message Middleware Plugins
    • Encoding Plugins
    • Security and Authentication Plugins
    • Distributed Tracing Plugins
    • Cache Plugins
    • Object Storage Plugins (OSS)
    • Rate Limiting Plugins
    • Metrics Plugins
    • AI Plugins
    • Workflow Plugins
    • Database and Cache Plugins
    • Bootstrap Integration and Gateway Plugins
    • Compression and Serialization Plugins
    • Template Rendering and Validation Plugins
  • go-wind-bootstrap

    • go-wind-bootstrap: The Declarative Bootstrap
    • The Bootstrap Configuration System
    • The Bootstrap SPI Mechanism
    • Declarative Middleware Orchestration
    • Bootstrap Command-Line Integration
    • Bootstrap Practical Examples
  • go-wind-flow Workflow Engine

    • GoWind Flow Process Engine
  • Tutorials

    • Quick Start Tutorial
    • Custom Plugin Development Tutorial
    • Multi-Protocol Listening Tutorial
    • Framework Migration Guide

go-wind-bootstrap: The Declarative Bootstrap

go-wind-bootstrap is the topmost layer of the GoWind ecosystem. Through declarative YAML configuration, it assembles the go-wind core and go-wind-plugins into a complete application, achieving "zero-code startup".

1. Design Philosophy

The core defines interfaces, plugins provide implementations, and the Bootstrap handles assembly.

┌──────────────────────────────────────────┐
│         Bootstrap (Assembly Layer)       │
│  BootstrapConfig → Builder Registry      │
│       → wind.Option chain → wind.App     │
├──────────────────────────────────────────┤
│         Adapters / Plugins (Impl. Layer) │
│   HTTP/gRPC/Zap/Redis/Consul/Kafka/...   │
├──────────────────────────────────────────┤
│         Core (Interface Layer)           │
│   transport.Server / log.Logger          │
└──────────────────────────────────────────┘

2. Hello World

2.1 config.yaml

app:
  id: my-service
  name: my-service
  version: "1.0.0"
  env: development

server:
  http:
    addr: ":8080"

logger:
  type: zap
  zap:
    level: info
    format: json

2.2 main.go

package main

import (
    "fmt"
    "net/http"
    "os"

    bootstrap "github.com/tx7do/go-wind-bootstrap"
    _ "github.com/tx7do/go-wind-bootstrap/log/zap"
    httpAdapter "github.com/tx7do/go-wind-bootstrap/transport/http"
)

func main() {
    httpAdapter.RegisterServerSetup(func(srv *httpAdapter.Server) {
        srv.GET("/", func(w http.ResponseWriter, r *http.Request) {
            _, _ = fmt.Fprintf(w, "Hello, GoWind!\n")
        })
    })

    if err := bootstrap.RunAppWithFlags(bootstrap.NewCommandFlags()); err != nil {
        os.Exit(1)
    }
}

2 blank imports + one startup line is all it takes to run a service with an HTTP server and logging:

go run main.go                       # Use the default config.yaml
go run main.go -c /path/to/config.yaml  # Specify a configuration file

3. Bootstrap vs. Manual Assembly

3.1 Manual Assembly (Without the Bootstrap)

func main() {
    // 1. Create the logger
    logger := zapPlugin.NewLogger(zapPlugin.WithLevel("info"))
    log.SetLogger(logger)

    // 2. Create the database connection
    db, _ := mysqlPlugin.New(mysqlPlugin.WithDSN("..."))
    client := ent.NewClient(ent.Driver(db))

    // 3. Create the cache
    cache, _ := redisPlugin.New(redisPlugin.WithAddr("localhost:6379"))

    // 4. Create the Broker
    kafka, _ := kafkaPlugin.New(kafkaPlugin.WithAddrs("localhost:9092"))

    // 5. Create the HTTP server
    router := setupRouter(client, cache, kafka)
    httpServer := httpPlugin.NewServer(
        httpPlugin.WithAddr(":8080"),
        httpPlugin.WithHandler(router),
    )

    // 6. Create the App (signal listening is built in, no extra options needed)
    app := wind.New(
        wind.WithName("my-service"),
        wind.WithServer(httpServer),
        wind.WithLogger(logger),
    )

    // 7. Start
    app.Run(context.Background())
}

3.2 Bootstrap: Declarative

func main() {
    // Everything is assembled automatically from YAML
    if err := bootstrap.RunApp("config.yaml"); err != nil {
        log.Fatal(err)
    }
}
AspectManual AssemblyBootstrap
Lines of code30+2
Configuration changesRequires code changes + recompilationEdit the YAML and restart
Adding a pluginWrite code to create + injectAdd a blank import + YAML config
Error troubleshootingAt compile timeAt runtime (needs log support)
FlexibilityHighMedium (convention over configuration)

4. Bootstrap Capabilities

CapabilityDescription
Declarative configurationA Protobuf-defined BootstrapConfig; one YAML/JSON/binary file describes the full application topology
SPI assemblyAdapters self-register Builders via init() and are instantiated automatically according to configuration
Lifecycle managementInitialize → Start → Run → Stop; signal listening built in (SIGINT/SIGTERM)
Service registry assemblyInstance registration is deferred until after the application has started (AfterStart hook) so it registers with real endpoints, and deregistered first at shutdown (BeforeStop hook)
Middleware orchestrationDeclare middleware chains in YAML, enabled in proto field order
Multi-instance managementMulti-instance support for databases/caches/brokers/storage etc., retrieved by type key
Multi-format configurationYAML / JSON / Protobuf binary, auto-detected by file extension

Field Mapping Code Generation

The field mappings of the Bootstrap configuration surface are no longer maintained by hand: the mapping from each family's configuration fields to upstream library options is generated declaratively by protoc-gen-fieldmap according to the spec, and CI regenerates from the spec and compares byte-by-byte to prevent drift between the configuration surface and upstream library options. See protoc-gen-fieldmap: The Field Mapping Generator for details.

5. Configuration File Loading

The startup entry point specifies the configuration file via a Cobra command-line flag (-c/--conf, default config.yaml), with the format auto-detected by extension:

go run main.go -c /path/to/config.yaml   # YAML
go run main.go -c config.json            # JSON
go run main.go -c config.pb              # Protobuf binary
// Fully sealed: internally goes through RunApp → LoadConfigFromFile
bootstrap.RunAppWithFlags(bootstrap.NewCommandFlags())

// Semi-sealed: load the configuration first, manipulate it, then run
cfg, _ := bootstrap.LoadConfigFromFile("config.yaml")
bctx, _ := bootstrap.BootstrapWithContext(nil, cfg)
fmt.Println(bctx.Config().GetApp().GetName())
bctx.App().Run(bctx)

Besides the main configuration file, you can also configure configuration center sources (file / etcd / nacos / consul / apollo, etc.) to pull remote configuration at startup — see The Bootstrap Configuration System.

6. Directory Conventions

my-service/
├── cmd/
│   └── server/
│       └── main.go          # Entry point
├── configs/
│   └── config.yaml          # Configuration file
├── ent/                     # Ent entity definitions
├── api/                     # Protobuf API definitions
├── internal/
│   ├── service/             # Business logic layer
│   ├── repo/                # Data access layer
│   └── router/              # Route configuration
├── go.mod
└── go.sum

7. Multi-Module Dependency Isolation

The bootstrap engine core depends only on go-wind, Cobra, and Protobuf (the configuration contract). Every adapter subpackage (log/zap, transport/http, database/gorm, cache/redis…) is a submodule with its own go.mod — only the adapters you use are imported, and unused adapters never enter the dependency tree.

Related Documentation

  • The Bootstrap Configuration System
  • The Bootstrap SPI Mechanism
  • Declarative Middleware Orchestration
  • Quick Start Tutorial
  • Framework Architecture
Edit this page
Last Updated:: 11/3/26, 2:14 PM
Contributors: Bobo
Next
The Bootstrap Configuration System