Files
go-micro/micro.go
T
Asim AslamandClaude cad0ff1e49 Claude/update docs roadmap f zd2 j (#2872)
* 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

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 10:50:00 +00:00

109 lines
2.8 KiB
Go

// Package micro is a pluggable framework for microservices
package micro
import (
"context"
"go-micro.dev/v5/client"
"go-micro.dev/v5/server"
"go-micro.dev/v5/service"
)
type serviceKey struct{}
// Service is an interface that wraps the lower level libraries
// within go-micro. Its a convenience method for building
// and initializing services.
type Service interface {
// The service name
Name() string
// Init initializes options
Init(...Option)
// Options returns the current options
Options() Options
// Register the handler
Handle(v interface{}) error
// Client is used to call services
Client() client.Client
// Server is for handling requests and events
Server() server.Server
// Start the service
Start() error
// Stop the service
Stop() error
// Run the service (start, block on signal, then stop)
Run() error
// The service implementation
String() string
}
// Group is a set of services that share lifecycle management.
type Group = service.Group
type Option = service.Option
type Options = service.Options
// Event is used to publish messages to a topic.
type Event interface {
// Publish publishes a message to the event topic
Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error
}
// Type alias to satisfy the deprecation.
type Publisher = Event
// New represents the new service
func New(name string) Service {
return NewService(
service.Name(name),
)
}
// NewService creates and returns a new Service based on the packages within.
func NewService(opts ...Option) Service {
return service.New(opts...)
}
// NewGroup creates a service group for running multiple services
// in a single binary with shared lifecycle management.
func NewGroup(svcs ...Service) *Group {
var ss []*service.ServiceImpl
for _, s := range svcs {
if si, ok := s.(*service.ServiceImpl); ok {
ss = append(ss, si)
}
}
return service.NewGroup(ss...)
}
// FromContext retrieves a Service from the Context.
func FromContext(ctx context.Context) (Service, bool) {
s, ok := ctx.Value(serviceKey{}).(Service)
return s, ok
}
// NewContext returns a new Context with the Service embedded within it.
func NewContext(ctx context.Context, s Service) context.Context {
return context.WithValue(ctx, serviceKey{}, s)
}
// NewEvent creates a new event publisher.
func NewEvent(topic string, c client.Client) Event {
if c == nil {
c = client.NewClient()
}
return &event{c, topic}
}
// RegisterHandler is syntactic sugar for registering a handler.
func RegisterHandler(s server.Server, h interface{}, opts ...server.HandlerOption) error {
return s.Handle(s.NewHandler(h, opts...))
}
// RegisterSubscriber is syntactic sugar for registering a subscriber.
func RegisterSubscriber(topic string, s server.Server, h interface{}, opts ...server.SubscriberOption) error {
return s.Subscribe(s.NewSubscriber(topic, h, opts...))
}