The simplest go-micro service demonstrating core concepts.
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
go run main.goThe service will start and make test calls to itself, then wait for incoming requests.
curl -X POST http://localhost:8080 \
-H 'Content-Type: application/json' \
-H 'Micro-Endpoint: Greeter.Hello' \
-d '{"name": "Alice"}'Expected response:
{"message": "Hello Alice"}micro call greeter Greeter.Hello '{"name": "Bob"}'- Define types - Request and Response structures
- Implement handler - The
Greeterservice withHellomethod - Create service - Using
micro.NewService()with options - Register handler - Link the handler to the service
- Run service - Start listening for requests
- 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
- See pubsub-events for event-driven patterns
- See production-ready for a complete example
- Read the Getting Started Guide