|
| 1 | +# Quick Start |
| 2 | + |
| 3 | +Get up and running with go-micro in under 5 minutes. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```bash |
| 8 | +go install go-micro.dev/v5/cmd/micro@latest |
| 9 | +``` |
| 10 | + |
| 11 | +## Create Your First Service |
| 12 | + |
| 13 | +```bash |
| 14 | +# Create a new service |
| 15 | +micro new helloworld |
| 16 | +cd helloworld |
| 17 | + |
| 18 | +# Review the generated code |
| 19 | +ls -la |
| 20 | + |
| 21 | +# Run locally with hot reload |
| 22 | +micro run |
| 23 | + |
| 24 | +# Test it |
| 25 | +curl -X POST http://localhost:8080/api/helloworld/Helloworld.Call \ |
| 26 | + -H "Content-Type: application/json" \ |
| 27 | + -d '{"name": "World"}' |
| 28 | +``` |
| 29 | + |
| 30 | +## Next Steps |
| 31 | + |
| 32 | +- **[Full Tutorial](getting-started.md)** - In-depth guide |
| 33 | +- **[Examples](examples/)** - Learn by example |
| 34 | +- **[API Reference](https://pkg.go.dev/go-micro.dev/v5)** - Complete API docs |
| 35 | +- **[Deployment](deployment.md)** - Deploy to production |
| 36 | + |
| 37 | +## Common Patterns |
| 38 | + |
| 39 | +### RPC Service |
| 40 | +```go |
| 41 | +package main |
| 42 | + |
| 43 | +import "go-micro.dev/v5" |
| 44 | + |
| 45 | +type Greeter struct{} |
| 46 | + |
| 47 | +func (g *Greeter) Hello(ctx context.Context, req *Request, rsp *Response) error { |
| 48 | + rsp.Message = "Hello " + req.Name |
| 49 | + return nil |
| 50 | +} |
| 51 | + |
| 52 | +func main() { |
| 53 | + service := micro.New("greeter") |
| 54 | + service.Handle(new(Greeter)) |
| 55 | + service.Run() |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +### Pub/Sub Event Handler |
| 60 | +```go |
| 61 | +import "go-micro.dev/v5" |
| 62 | + |
| 63 | +func main() { |
| 64 | + service := micro.New("subscriber") |
| 65 | + |
| 66 | + // Subscribe to events |
| 67 | + micro.RegisterSubscriber("user.created", service.Server(), |
| 68 | + func(ctx context.Context, event *UserCreatedEvent) error { |
| 69 | + log.Infof("User created: %s", event.Email) |
| 70 | + return nil |
| 71 | + }, |
| 72 | + ) |
| 73 | + |
| 74 | + service.Run() |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Publishing Events |
| 79 | +```go |
| 80 | +publisher := micro.NewEvent("user.created", client) |
| 81 | +publisher.Publish(ctx, &UserCreatedEvent{ |
| 82 | + Email: "user@example.com", |
| 83 | +}) |
| 84 | +``` |
| 85 | + |
| 86 | +## Get Help |
| 87 | + |
| 88 | +- **[Discord Community](https://discord.gg/jwTYuUVAGh)** - Chat with other users |
| 89 | +- **[GitHub Issues](https://github.com/micro/go-micro/issues)** - Report bugs or request features |
| 90 | +- **[Documentation](https://go-micro.dev/docs/)** - Complete docs |
| 91 | + |
0 commit comments