The Principal Dev – Masterclass for Tech Leads

The Principal Dev – Masterclass for Tech LeadsJuly 17-18

Join

Go Micro Go.Dev reference Go Report Card

Go Micro is a framework for distributed systems development.

Overview

Go Micro provides the core requirements for distributed systems development including RPC and Event driven communication. The Go Micro philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly but everything can be easily swapped out.

Features

Go Micro abstracts away the details of distributed systems. Here are the main features.

Getting Started

To make use of Go Micro import it

import "go-micro.dev/v5"

Create a service and register a handler

package main

import (
        "go-micro.dev/v5"
)

type Request struct {
        Name string `json:"name"`
}

type Response struct {
        Message string `json:"message"`
}

type Say struct{}

func (h *Say) Hello(ctx context.Context, req *Request, rsp *Response) error {
        rsp.Message = "Hello " + req.Name
        return nil
}

func main() {
        // create the service
        service := micro.New("helloworld")

        // register handler
        service.Handle(new(Say))

        // run the service
        service.Run()
}

Optionally set fixed address

service := micro.NewService(
    micro.Address(":8080"),
)

Call it via curl

curl -XPOST \
     -H 'Content-Type: application/json' \
     -H 'Micro-Endpoint: Say.Hello' \
     -d '{"name": "alice"}' \
      http://localhost:8080

Micro

Use the Micro cli to call it

micro call helloworld Say.Hello '{"name": "Asim"}'

Run the micro api and call it via http

micro api

Call it via http://localhost:8080/

curl -d '{"name": "Asim"}' https://localhost:8080/helloworld/Say/Hello

Protobuf

Protobuf is supported via protoc-gen-micro

Plugins

See Plugins for implementations of the various core interfaces.

Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.