-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
94 lines (94 loc) · 4.15 KB
/
Copy pathdoc.go
File metadata and controls
94 lines (94 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Package mx is a composable Go microservices framework built around a central
// Launcher that orchestrates independent services through a services runner.
//
// MX gives every service a well-defined lifecycle (idle → starting → running →
// stopping → stopped/failed), graceful shutdown on OS signals, health checks,
// metrics, profiling, and ready-made HTTP/gRPC/ConnectRPC transports and clients.
//
// # Getting started
//
// go get github.com/tkcrm/mx@latest
//
// A minimal application wires a logger, registers services with the launcher,
// and blocks on Run:
//
// l := logger.NewExtended(logger.WithAppName("app"))
//
// ln := launcher.New(
// launcher.WithName("app"),
// launcher.WithVersion("v1.0.0"),
// launcher.WithLogger(l),
// )
//
// ln.ServicesRunner().Register(
// launcher.NewService(launcher.WithService(mySvc)),
// )
//
// if err := ln.Run(); err != nil { // blocks until shutdown
// log.Fatal(err)
// }
//
// # Services
//
// A service is any value implementing the [github.com/tkcrm/mx/launcher/lntypes.IService]
// interface (Name, Start, Stop). Start must block until its context is cancelled
// or its work is done. Wrap a service with [github.com/tkcrm/mx/launcher.NewService]
// and [github.com/tkcrm/mx/launcher.WithService], which duck-types the value for
// the optional lntypes.Enabler and lntypes.HealthChecker interfaces as well.
//
// # Startup priority
//
// Services are started in ascending startup-priority groups. All services in a
// group must become ready before the next group starts, while services within a
// group start concurrently. This lets infrastructure such as databases and
// message queues come up first, with the rest of the application starting only
// once they are ready. Priority 0 (the default) starts last, after every
// prioritized group is ready:
//
// ln.ServicesRunner().Register(
// launcher.NewService(launcher.WithService(db), launcher.WithStartupPriority(1)),
// launcher.NewService(launcher.WithService(queue), launcher.WithStartupPriority(1)),
// launcher.NewService(launcher.WithService(app)), // priority 0 → starts last
// )
//
// "Ready" is what a service reports through the optional
// [github.com/tkcrm/mx/mxtypes.ReadinessReporter] interface (or the
// [github.com/tkcrm/mx/launcher.WithReadiness] option): a database becomes ready
// once it has connected, an HTTP server once it is listening. A service that
// does not report readiness is considered ready as soon as its Start goroutine
// is launched, so to truly gate a group behind infrastructure that service must
// report readiness. StartupTimeout bounds the wait for this signal.
//
// Shutdown order is controlled independently via
// [github.com/tkcrm/mx/launcher.WithRunnerServicesSequence] (None/Fifo/Lifo).
//
// # Restart policies
//
// Per-service restart behaviour is configured with
// [github.com/tkcrm/mx/launcher.WithRestartPolicy]: RestartOnFailure or
// RestartAlways, with a bounded number of retries and exponential backoff.
//
// # Ops
//
// When ops are enabled via [github.com/tkcrm/mx/launcher.WithOpsConfig], the
// launcher runs a dedicated HTTP server (default port 10000) exposing a liveness
// probe (/livez), a readiness probe (/readyz), a legacy health endpoint
// (/healthy), Prometheus metrics (/metrics), and the pprof profiler
// (/debug/pprof).
//
// # Subpackages
//
// - launcher — service orchestration, lifecycle, restart policies, ops wiring.
// - launcher/lntypes — core interfaces (IService, HealthChecker, Enabler,
// StateProvider) and ServiceState.
// - launcher/ops — health, metrics, and profiler operational services.
// - logger — structured logging backed by go.uber.org/zap.
// - transport/http_transport — net/http server as a managed service.
// - transport/grpc_transport — gRPC server with interceptors, health, reflection.
// - transport/connectrpc_transport — ConnectRPC (gRPC-compatible) server.
// - clients/grpc_client, clients/connectrpc_client — generic client factories.
// - util — assorted helpers (JSON, structs, files, timing).
//
// All MX components follow the functional-options pattern (WithXxx). See the
// package-level documentation of each subpackage for details.
package mx