Go Micro basics: writing, discovering and calling services in Go

Go Micro is a Go framework for RPC services. You write a struct whose methods are handlers, and Go Micro registers the service in a registry, finds other services by name, picks an instance to call, and encodes requests (JSON by default, protobuf if you use it). Each of those parts (registry, selector, transport, codec, broker) is an interface you can swap.
The micro CLI’s install instructions ask for Go 1.26 or newer.
mkdir hello-service && cd hello-servicego mod init example.com/hello-servicego get go-micro.dev/v6@latestgo install go-micro.dev/v6/cmd/micro@latestA hello service
Section titled “A hello service”main.go:
package main
import ( "context" "log"
"go-micro.dev/v6")
type HelloRequest struct { Name string `json:"name"`}
type HelloResponse struct { Msg string `json:"msg"`}
type Greeter struct{}
func (g *Greeter) Hello(ctx context.Context, req *HelloRequest, rsp *HelloResponse) error { rsp.Msg = "Hello, " + req.Name return nil}
func main() { service := micro.NewService("hello") service.Init()
if err := service.Handle(new(Greeter)); err != nil { log.Fatal(err) } if err := service.Run(); err != nil { log.Fatal(err) }}Each exported method with the shape (ctx, *Request, *Response) error becomes an endpoint named Type.Method, here Greeter.Hello. service.Init() also parses command-line flags, so options such as the registry can be set at startup.
Run it, then call it from another terminal:
go run .micro call hello Greeter.Hello '{"name": "John"}'{"msg": "Hello, John"}Service discovery
Section titled “Service discovery”The default registry is multicast DNS (registry.NewMDNSRegistry()), which works on a single machine or LAN with no extra infrastructure. It does not work where multicast is blocked, which includes most cloud networks and many container setups. For those, use a shared registry. Consul is one option:
import ( "go-micro.dev/v6" "go-micro.dev/v6/registry" "go-micro.dev/v6/registry/consul")
func main() { service := micro.NewService("hello", micro.Registry(consul.NewConsulRegistry( registry.Addrs("127.0.0.1:8500"), )), ) // ...}Every service and client that should see each other must use the same registry. A local Consul agent for testing can be started with consul agent -dev.
Calling a service from Go
Section titled “Calling a service from Go”Clients look services up by name, so the caller never needs an address. This client lives in its own module or directory and declares matching request and response types:
package main
import ( "context" "fmt" "log" "time"
"go-micro.dev/v6" "go-micro.dev/v6/client")
type HelloRequest struct { Name string `json:"name"`}
type HelloResponse struct { Msg string `json:"msg"`}
func main() { service := micro.NewService("hello.client") service.Init()
c := service.Client() req := c.NewRequest("hello", "Greeter.Hello", &HelloRequest{Name: "John"})
var rsp HelloResponse err := c.Call(context.Background(), req, &rsp, client.WithRetries(3), client.WithRequestTimeout(5*time.Second), ) if err != nil { log.Fatal(err) } fmt.Println(rsp.Msg)}Load balancing
Section titled “Load balancing”Load balancing is done on the client. For each call, the client’s selector gets the list of hello instances from the registry and picks one. The default strategy is random, not round-robin; selector.RoundRobin is available if you build a selector with selector.SetStrategy(selector.RoundRobin) and pass it to the client with client.Selector(...).
To see it, start two or three copies of the service (each picks a free port and registers itself) and call it repeatedly. Calls spread across instances, but with the random strategy not in a strict rotation.
Retries and timeouts
Section titled “Retries and timeouts”Instead of a separate circuit-breaker plugin, start with the client’s own settings:
client.DefaultRetriesis 5 andclient.DefaultRequestTimeoutis 30 seconds.- Override them per call with
client.WithRetriesandclient.WithRequestTimeout, as in the client above, or for the whole client withclient.Retriesandclient.RequestTimeout. client.Retry(fn)sets which errors are retried.
Retries on a call that changes state are only safe if the handler is idempotent.
If you need a real circuit breaker, wrap the client with micro.WrapClient(...) and implement the breaker in a client.Wrapper, for example around a library such as sony/gobreaker.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)