micro--go-micro
fad2fd7af4
* docs: update all four documentation guides and mark Q2 complete - ai-native-services: add WithMCP one-liner, standalone gateway, WebSocket client example, and OpenTelemetry observability section - mcp-security: add OTel distributed tracing, WebSocket authentication (connection-level and per-message), DeniedReason audit field - tool-descriptions: add manual overrides with WithEndpointDocs and export formats section - agent-patterns: add LangChain/LlamaIndex SDK pattern and standalone gateway production pattern with Docker example - Update roadmap: mark Q2 documentation as complete, Q2 at 100% - Update status: reflect all recent completions, shift priorities https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: add agent demo example and blog post Add examples/agent-demo with a multi-service project management app (projects, tasks, team) that demonstrates AI agents interacting with Go Micro services through MCP. Includes seed data and example prompts. Add blog post 4 "Agents Meet Microservices: A Hands-On Demo" walking through the example code and showing cross-service agent workflows. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: enable multiple services in a single binary Remove global state mutations from service and cmd option functions so that configuring one service no longer overwrites another's settings. Key changes: - service/options.go: remove all DefaultXxx global writes from option functions; newOptions() now creates fresh Server, Client, Store, and Cache per service while sharing Registry, Broker, and Transport - cmd/cmd.go: newCmd() uses local copies instead of pointers to package globals; Before() no longer mutates DefaultXxx vars - cmd/options.go: remove global mutations from all option functions - service/service.go: export ServiceImpl type for cross-package use - service/group.go: new Group type for multi-service lifecycle - micro.go: add Start/Stop to Service interface, expose Group and NewGroup convenience function - examples/multi-service: working example with two services https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * docs: highlight multi-service binary support Add multi-service section to README with code example, update features list, add to examples index, and note in status summary. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: unify service API and clean up developer experience - Unified service creation: micro.New("name", opts...) as canonical API - Clean handler registration: service.Handle(handler, opts...) accepts server.HandlerOption args directly, no need to reach through Server() - Unexported serviceImpl: users interact through Service interface only - Service groups use Service interface (not concrete type) - Fixed Stop() to properly propagate BeforeStop/AfterStop errors - Fixed store init: error-level log instead of fatal on init failure - Updated all examples to use consistent patterns - Updated README, getting-started, MCP docs, and guides - Added blog post about the DX cleanup https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * fix: add blog post 5 to blog index Blog post 5 (Developer Experience Cleanup) existed as a file but was missing from the blog index page. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * feat: make micro new generate MCP-enabled services by default - main.go template includes mcp.WithMCP(":3001") by default - Handler template has agent-friendly doc comments with @example tags - Proto template has descriptive field comments - README includes MCP usage, Claude Code config, and tool description tips - Makefile adds mcp-tools, mcp-test, mcp-serve targets - go.mod updated to Go 1.22 - Added --no-mcp flag to opt out of MCP integration - Post-create output shows MCP endpoint URLs https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc --------- Co-authored-by: Claude <noreply@anthropic.com>
72 行
1.5 KiB
Go
72 行
1.5 KiB
Go
package template
|
|
|
|
var (
|
|
HandlerSRV = `package handler
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "go-micro.dev/v5/logger"
|
|
|
|
pb "{{.Dir}}/proto"
|
|
)
|
|
|
|
type {{title .Alias}} struct{}
|
|
|
|
// Return a new handler.
|
|
func New() *{{title .Alias}} {
|
|
return &{{title .Alias}}{}
|
|
}
|
|
|
|
// Call greets a person by name and returns a welcome message.
|
|
//
|
|
// @example {"name": "Alice"}
|
|
func (e *{{title .Alias}}) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
|
|
log.Info("Received {{title .Alias}}.Call request")
|
|
rsp.Msg = "Hello " + req.Name
|
|
return nil
|
|
}
|
|
|
|
// Stream sends a sequence of numbered responses back to the caller.
|
|
// Use this for streaming large result sets or real-time updates.
|
|
//
|
|
// @example {"count": 5}
|
|
func (e *{{title .Alias}}) Stream(ctx context.Context, req *pb.StreamingRequest, stream pb.{{title .Alias}}_StreamStream) error {
|
|
log.Infof("Received {{title .Alias}}.Stream request with count: %d", req.Count)
|
|
|
|
for i := 0; i < int(req.Count); i++ {
|
|
log.Infof("Responding: %d", i)
|
|
if err := stream.Send(&pb.StreamingResponse{
|
|
Count: int64(i),
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
`
|
|
|
|
SubscriberSRV = `package subscriber
|
|
|
|
import (
|
|
"context"
|
|
log "go-micro.dev/v5/logger"
|
|
|
|
pb "{{.Dir}}/proto"
|
|
)
|
|
|
|
type {{title .Alias}} struct{}
|
|
|
|
func (e *{{title .Alias}}) Handle(ctx context.Context, msg *pb.Message) error {
|
|
log.Info("Handler Received message: ", msg.Say)
|
|
return nil
|
|
}
|
|
|
|
func Handler(ctx context.Context, msg *pb.Message) error {
|
|
log.Info("Function Received message: ", msg.Say)
|
|
return nil
|
|
}
|
|
`
|
|
)
|