Convert Figma logo to code with AI

micro logogo-micro

A Go microservices framework

21,881
2,351
21,881
7

Top Related Projects

26,556

A standard library for microservices.

20,988

The Go language implementation of gRPC. HTTP/2 based RPC

77,851

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

29,410

High performance, minimalist Go web framework

20,665

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍

33,019

⚡️ Express inspired web framework written in Go

Quick Overview

Go Micro is a framework for distributed systems development in Go. It provides the core requirements for distributed systems development including RPC and event-driven communication. Go Micro abstracts away the details of distributed systems, allowing developers to focus on building business logic.

Pros

  • Simplifies the development of microservices in Go
  • Provides a pluggable architecture for flexibility and extensibility
  • Offers built-in service discovery, load balancing, and fault tolerance
  • Supports multiple protocols (gRPC, HTTP, etc.) and encodings

Cons

  • Learning curve for developers new to microservices architecture
  • May be overkill for simple applications or small projects
  • Documentation can be sparse or outdated in some areas
  • Community support might be less compared to some other frameworks

Code Examples

  1. Defining a service:
import (
    "github.com/micro/go-micro/v3"
)

service := micro.NewService(
    micro.Name("greeter"),
    micro.Version("latest"),
)
service.Init()
  1. Implementing a handler:
type Greeter struct{}

func (g *Greeter) Hello(ctx context.Context, req *proto.Request, rsp *proto.Response) error {
    rsp.Greeting = "Hello " + req.Name
    return nil
}
  1. Calling a service:
client := proto.NewGreeterService("greeter", service.Client())
rsp, err := client.Hello(context.Background(), &proto.Request{Name: "John"})
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(rsp.Greeting)

Getting Started

  1. Install Go Micro:

    go get github.com/micro/go-micro/v3
    
  2. Create a new service:

    package main
    
    import (
        "github.com/micro/go-micro/v3"
        "log"
    )
    
    func main() {
        service := micro.NewService(
            micro.Name("my.service"),
        )
    
        service.Init()
    
        if err := service.Run(); err != nil {
            log.Fatal(err)
        }
    }
    
  3. Run the service:

    go run main.go
    

Competitor Comparisons

26,556

A standard library for microservices.

Pros of kit

  • More flexible and modular architecture, allowing developers to pick and choose components
  • Extensive documentation and examples for various use cases
  • Strong focus on observability with built-in support for metrics, tracing, and logging

Cons of kit

  • Steeper learning curve due to its flexibility and numerous concepts
  • Requires more boilerplate code to set up services
  • Less opinionated, which may lead to inconsistencies across projects

Code Comparison

kit example:

func main() {
    svc := service.New(myService{})
    endpoints := endpoint.New(svc)
    http.ListenAndServe(":8080", endpoints)
}

go-micro example:

func main() {
    service := micro.NewService(micro.Name("my.service"))
    service.Init()
    micro.RegisterHandler(service.Server(), new(Handler))
    service.Run()
}

The kit example shows a more explicit setup process, while go-micro provides a more streamlined approach with built-in service discovery and registration. go-micro offers a higher level of abstraction, making it easier to get started but potentially less flexible for complex scenarios. kit's modular design allows for more customization but requires more setup code.

20,988

The Go language implementation of gRPC. HTTP/2 based RPC

Pros of grpc-go

  • More widely adopted and battle-tested in production environments
  • Extensive documentation and community support
  • Highly performant with efficient binary serialization

Cons of grpc-go

  • Steeper learning curve, especially for developers new to gRPC
  • Requires more boilerplate code for setup and configuration
  • Limited to gRPC-specific communication patterns

Code Comparison

grpc-go:

s := grpc.NewServer()
pb.RegisterGreeterServer(s, &server{})
lis, err := net.Listen("tcp", ":50051")
if err != nil {
    log.Fatalf("failed to listen: %v", err)
}
if err := s.Serve(lis); err != nil {
    log.Fatalf("failed to serve: %v", err)
}

go-micro:

service := micro.NewService(
    micro.Name("greeter"),
)
service.Init()
pb.RegisterGreeterHandler(service.Server(), &Greeter{})
if err := service.Run(); err != nil {
    fmt.Println(err)
}

Summary

grpc-go is a robust, high-performance gRPC implementation with extensive community support, while go-micro offers a more abstracted, microservices-oriented framework. grpc-go excels in raw performance and gRPC-specific features, whereas go-micro provides a more flexible, plugin-based architecture for building microservices with various communication protocols.

77,851

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Pros of gin

  • Lightweight and fast HTTP web framework
  • Simple and intuitive API for building web applications
  • Extensive middleware support for easy customization

Cons of gin

  • Limited to HTTP-based applications
  • Lacks built-in support for microservices architecture
  • Requires additional libraries for advanced features like service discovery

Code Comparison

gin example:

r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
    c.JSON(200, gin.H{"message": "pong"})
})
r.Run()

go-micro example:

service := micro.NewService(micro.Name("greeter"))
service.Init()
proto.RegisterGreeterHandler(service.Server(), new(Greeter))
service.Run()

Summary

gin is a lightweight HTTP web framework focused on simplicity and performance, while go-micro is a more comprehensive framework for building microservices. gin excels in creating HTTP-based applications quickly, but lacks built-in microservices features. go-micro provides a complete toolkit for microservices development, including service discovery and message encoding, but may be overkill for simple web applications. Choose gin for straightforward web projects and go-micro for complex, distributed systems.

29,410

High performance, minimalist Go web framework

Pros of Echo

  • Lightweight and minimalist web framework, focusing on HTTP routing and middleware
  • Excellent performance and low memory footprint
  • Simple and intuitive API, making it easy to learn and use

Cons of Echo

  • Limited built-in features compared to full-stack microservices frameworks
  • Less suitable for complex distributed systems and microservices architectures
  • Smaller ecosystem and fewer plugins/extensions available

Code Comparison

Echo:

e := echo.New()
e.GET("/", func(c echo.Context) error {
    return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))

go-micro:

service := micro.NewService(
    micro.Name("helloworld"),
)
service.Init()
proto.RegisterGreeterHandler(service.Server(), new(Greeter))
if err := service.Run(); err != nil {
    fmt.Println(err)
}

Key Differences

  • Echo is primarily a web framework, while go-micro is a microservices framework
  • go-micro provides more built-in features for distributed systems, such as service discovery and load balancing
  • Echo focuses on HTTP routing and middleware, while go-micro offers a broader range of communication protocols
  • go-micro has a steeper learning curve but offers more scalability for complex microservices architectures
  • Echo is better suited for simpler web applications or APIs, while go-micro excels in distributed systems
20,665

Package gorilla/mux is a powerful HTTP router and URL matcher for building Go web servers with 🦍

Pros of gorilla/mux

  • Lightweight and focused solely on HTTP routing
  • Easy to learn and use, with a straightforward API
  • Highly flexible and customizable for specific routing needs

Cons of gorilla/mux

  • Limited to HTTP routing, lacking built-in support for microservices architecture
  • Requires additional libraries for more complex features like service discovery or load balancing

Code Comparison

gorilla/mux:

r := mux.NewRouter()
r.HandleFunc("/api/{key}", ApiHandler)
r.HandleFunc("/", HomeHandler)
http.ListenAndServe(":8080", r)

go-micro:

service := micro.NewService(
    micro.Name("my.service"),
)
service.Init()
proto.RegisterGreeterHandler(service.Server(), new(Greeter))
service.Run()

Key Differences

  • go-micro is a comprehensive microservices framework, while gorilla/mux focuses on HTTP routing
  • go-micro provides built-in support for service discovery, load balancing, and message encoding
  • gorilla/mux offers more granular control over HTTP routing and middleware
  • go-micro is better suited for complex, distributed systems, while gorilla/mux excels in simpler web applications

Use Cases

  • Choose gorilla/mux for straightforward web applications or APIs with custom routing requirements
  • Opt for go-micro when building a microservices-based architecture with multiple interconnected services
33,019

⚡️ Express inspired web framework written in Go

Pros of Fiber

  • Extremely fast and lightweight web framework
  • Express-inspired API, making it easy for Node.js developers to transition
  • Built-in support for WebSocket, middleware, and static file serving

Cons of Fiber

  • Focused primarily on HTTP services, less suitable for complex microservices architectures
  • Smaller ecosystem and community compared to Go-Micro
  • Limited built-in support for service discovery and load balancing

Code Comparison

Fiber example:

app := fiber.New()

app.Get("/", func(c *fiber.Ctx) error {
    return c.SendString("Hello, World!")
})

app.Listen(":3000")

Go-Micro example:

service := micro.NewService(
    micro.Name("helloworld"),
)

service.Init()

proto.RegisterGreeterHandler(service.Server(), new(Greeter))

service.Run()

Go-Micro is more focused on building microservices with features like service discovery and message encoding, while Fiber is a lightweight web framework optimized for HTTP services. Go-Micro provides a more comprehensive toolkit for distributed systems, whereas Fiber excels in simplicity and performance for web applications. The choice between them depends on the specific requirements of your project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.

  • Authentication - Auth is built in as a first class citizen. Authentication and authorization enable secure zero trust networking by providing every service an identity and certificates. This additionally includes rule based access control.

  • Dynamic Config - Load and hot reload dynamic config from anywhere. The config interface provides a way to load application level config from any source such as env vars, file, etcd. You can merge the sources and even define fallbacks.

  • Data Storage - A simple data store interface to read, write and delete records. It includes support for many storage backends in the plugins repo. State and persistence becomes a core requirement beyond prototyping and Micro looks to build that into the framework.

  • Service Discovery - Automatic service registration and name resolution. Service discovery is at the core of micro service development. When service A needs to speak to service B it needs the location of that service. The default discovery mechanism is multicast DNS (mdns), a zeroconf system.

  • Load Balancing - Client side load balancing built on service discovery. Once we have the addresses of any number of instances 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 across the services and retry a different node if there's a problem.

  • Message Encoding - Dynamic message encoding based on content-type. The client and server will use codecs along with content-type to seamlessly encode and decode Go types for you. Any variety of messages could be encoded and sent from different clients. The client and server handle this by default. This includes protobuf and json by default.

  • RPC Client/Server - RPC based request/response with support for bidirectional streaming. We provide an abstraction for synchronous communication. A request made to a service will be automatically resolved, load balanced, dialled and streamed.

  • Async Messaging - PubSub is built in as a first class citizen for asynchronous communication and event driven architectures. Event notifications are a core pattern in micro service development. The default messaging system is a HTTP event message broker.

  • Pluggable Interfaces - Go Micro makes use of Go interfaces for each distributed system abstraction. Because of this these interfaces are pluggable and allows Go Micro to be runtime agnostic. You can plugin any underlying technology.

Getting Started

To make use of Go Micro import it

import "go-micro.dev/v5"

Define a handler (protobuf is optionally supported - see example)

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

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

type Helloworld struct{}

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

Create, initialise and run the service

// create a new service
service := micro.NewService(
    micro.Name("helloworld"),
    micro.Handle(new(Helloworld)),
)

// initialise flags
service.Init()

// start the service
service.Run()

Optionally set fixed address

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

Call it via curl

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