go-micro.dev/v5@v5.12.0/README.md (about) 1 # Go Micro [](https://pkg.go.dev/go-micro.dev/v5?tab=doc) [](https://goreportcard.com/report/github.com/go-micro/go-micro) 2 3 Go Micro is a framework for distributed systems development. 4 5 **[📖 Documentation](https://go-micro.dev/docs/)** | [Sponsor the project](https://github.com/sponsors/micro) 6 7 ## Overview 8 9 Go Micro provides the core requirements for distributed systems development including RPC and Event driven communication. 10 The Go Micro philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly 11 but everything can be easily swapped out. 12 13 ## Features 14 15 Go Micro abstracts away the details of distributed systems. Here are the main features. 16 17 - **Authentication** - Auth is built in as a first class citizen. Authentication and authorization enable secure 18 zero trust networking by providing every service an identity and certificates. This additionally includes rule 19 based access control. 20 21 - **Dynamic Config** - Load and hot reload dynamic config from anywhere. The config interface provides a way to load application 22 level config from any source such as env vars, file, etcd. You can merge the sources and even define fallbacks. 23 24 - **Data Storage** - A simple data store interface to read, write and delete records. It includes support for many storage backends 25 in the plugins repo. State and persistence becomes a core requirement beyond prototyping and Micro looks to build that into the framework. 26 27 - **Service Discovery** - Automatic service registration and name resolution. Service discovery is at the core of micro service 28 development. When service A needs to speak to service B it needs the location of that service. The default discovery mechanism is 29 multicast DNS (mdns), a zeroconf system. 30 31 - **Load Balancing** - Client side load balancing built on service discovery. Once we have the addresses of any number of instances 32 of a service we now need a way to decide which node to route to. We use random hashed load balancing to provide even distribution 33 across the services and retry a different node if there's a problem. 34 35 - **Message Encoding** - Dynamic message encoding based on content-type. The client and server will use codecs along with content-type 36 to seamlessly encode and decode Go types for you. Any variety of messages could be encoded and sent from different clients. The client 37 and server handle this by default. This includes protobuf and json by default. 38 39 - **RPC Client/Server** - RPC based request/response with support for bidirectional streaming. We provide an abstraction for synchronous 40 communication. A request made to a service will be automatically resolved, load balanced, dialled and streamed. 41 42 - **Async Messaging** - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures. 43 Event notifications are a core pattern in micro service development. The default messaging system is a HTTP event message broker. 44 45 - **Pluggable Interfaces** - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces 46 are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology. 47 48 ## Getting Started 49 50 To make use of Go Micro 51 52 ```bash 53 go get go-micro.dev/v5@latest 54 ``` 55 56 Create a service and register a handler 57 58 ```go 59 package main 60 61 import ( 62 "go-micro.dev/v5" 63 ) 64 65 type Request struct { 66 Name string `json:"name"` 67 } 68 69 type Response struct { 70 Message string `json:"message"` 71 } 72 73 type Say struct{} 74 75 func (h *Say) Hello(ctx context.Context, req *Request, rsp *Response) error { 76 rsp.Message = "Hello " + req.Name 77 return nil 78 } 79 80 func main() { 81 // create the service 82 service := micro.New("helloworld") 83 84 // register handler 85 service.Handle(new(Say)) 86 87 // run the service 88 service.Run() 89 } 90 ``` 91 92 Set a fixed address 93 94 ```go 95 service := micro.NewService( 96 micro.Name("helloworld"), 97 micro.Address(":8080"), 98 ) 99 ``` 100 101 Call it via curl 102 103 ```bash 104 curl -XPOST \ 105 -H 'Content-Type: application/json' \ 106 -H 'Micro-Endpoint: Say.Hello' \ 107 -d '{"name": "alice"}' \ 108 http://localhost:8080 109 ``` 110 111 ## Experimental 112 113 There's a new `genai` package for generative AI capabilities. 114 115 ## Protobuf 116 117 Install the code generator and see usage in the docs: 118 119 ```bash 120 go install go-micro.dev/v5/cmd/protoc-gen-micro@latest 121 ``` 122 123 Docs: [`internal/website/docs/getting-started.md`](internal/website/docs/getting-started.md) 124 125 ## Command line 126 127 Install the CLI and see usage in the docs: 128 129 ``` 130 go install go-micro.dev/v5/cmd/micro@latest 131 ``` 132 133 Docs: [`internal/website/docs`](internal/website/docs) 134 135 Package reference: https://pkg.go.dev/go-micro.dev/v5 136 137 Selected topics: 138 - Getting Started: [`internal/website/docs/getting-started.md`](internal/website/docs/getting-started.md) 139 - Plugins overview: [`internal/website/docs/plugins.md`](internal/website/docs/plugins.md) 140 - Learn by Example: [`internal/website/docs/examples/index.md`](internal/website/docs/examples/index.md) 141 142 ## Adopters 143 144 - [Sourse](https://sourse.eu) - Work in the field of earth observation, including embedded Kubernetes running onboard aircraft, and we’ve built a mission management SaaS platform using Go Micro.