mirror of
https://github.com/go-micro/go-micro.git
synced 2026-06-15 19:35:13 +02:00
* Initial plan
* feat(health): add RegistryCheck for registry connectivity health checks
Add a RegistryCheck function to the health package that creates a health
check verifying connectivity to the service registry. This enables
Kubernetes readiness probes to detect when a service loses its connection
to the registry (e.g. etcd).
Usage:
health.Register("registry", health.RegistryCheck(reg))
* fix(health): simplify error assertion in registry check test
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Hello World Example
The simplest go-micro service demonstrating core concepts.
What It Does
This example creates a basic RPC service that:
- Listens on port 8080
- Exposes a
Greeter.Hellomethod - Returns a greeting message
- Demonstrates both programmatic and HTTP access
Run It
go run main.go
The service will start and make test calls to itself, then wait for incoming requests.
Test It
Using curl
curl -X POST http://localhost:8080 \
-H 'Content-Type: application/json' \
-H 'Micro-Endpoint: Greeter.Hello' \
-d '{"name": "Alice"}'
Expected response:
{"message": "Hello Alice"}
Using the micro CLI
micro call greeter Greeter.Hello '{"name": "Bob"}'
Code Walkthrough
- Define types - Request and Response structures
- Implement handler - The
Greeterservice withHellomethod - Create service - Using
micro.New()with options - Register handler - Link the handler to the service
- Run service - Start listening for requests
Key Concepts
- RPC Pattern: Method signature
func(ctx, req, rsp) error - Service Discovery: Automatic registration
- Multiple Transports: Works over HTTP, gRPC, etc.
- Type Safety: Strongly typed requests/responses
Next Steps
- See pubsub-events for event-driven patterns
- See production-ready for a complete example
- Read the Getting Started Guide