Go Micro examples. Contributions welcome!

Overview

Examples

This is a repository for go-micro examples. Feel free to contribute.

Contents

  • broker - A example of using Broker for Publish and Subscribing.
  • cache - Usage of the Cache package to create a cache service.
  • client - Usage of the Client package to call a service.
  • config - Using Go Config for dynamic config
  • event - Using the API Gateway event handler
  • filter - Filter nodes of a service when requesting
  • flags - Using command line flags with a service
  • function - Example of using Function programming model
  • getip - Get the local and remote ip from metadata
  • graceful - Demonstrates graceful shutdown of a service
  • greeter - A complete greeter example (includes python, ruby examples)
  • heartbeat - Make services heartbeat with discovery for high availability
  • helloworld - Hello world using micro
  • metadata - Extracting metadata from context of a request
  • mocking - Demonstrate mocking helloworld service
  • noproto - Use micro without protobuf or code generation, only go types
  • options - Setting options in the go-micro framework
  • plugins - How to use plugins
  • pubsub - Example of using pubsub at the client/server level
  • redirect - An example of how to http redirect using an API service
  • roundrobin - A stateful client wrapper for true round robin of requests
  • secure - Demonstrates use of transport secure option for self signed certs
  • server - Use of the Server package directly to server requests.
  • service - Example of the top level Service in go-micro.
  • sharding - An example of how to shard requests or use session affinity
  • shutdown - Demonstrates graceful shutdown via context cancellation
  • stream - An example of a streaming service and client
  • waitgroup - Demonstrates how to use a waitgroup with a service
  • wrapper - A simple example of using a log wrapper

Community

You might also like...
A RESTful caching micro-service in Go backed by Couchbase

Couchcache A caching service developed in Go. It provides REST APIs to access key-value pairs stored in Couchbase. You may also consider using couchca

Go Micro is a framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Micro is a platform for cloud native development
Micro is a platform for cloud native development

Micro Overview Micro addresses the key requirements for building services in the cloud. It leverages the microservices architecture pattern and provid

Go Micro is a framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Micro-service framework in Go
Micro-service framework in Go

Kite Micro-Service Framework Kite is a framework for developing micro-services in Go. Kite is both the name of the framework and the micro-service tha

Go Server/API micro framework, HTTP request router, multiplexer, mux
Go Server/API micro framework, HTTP request router, multiplexer, mux

🍃 gorouter Go Server/API micro framework, HTTP request router, multiplexer, mux. 📖 ABOUT Contributors: Rafał Lorenz Want to contribute ? Feel free t

Go micro-benchmarks for calculating the speed of language constructs

== About == Gospeed is a library of micro-benchmarks for Go which evolved from the GoLightly project. It's main utility is for understanding and reas

A code generator that turns plain old Go services into RPC-enabled (micro)services with robust HTTP APIs.

Frodo Frodo is a code generator and runtime library that helps you write RPC-enabled (micro) services and APIs. It parses the interfaces/structs/comme

NewSQL distributed storage database based on micro service framework
NewSQL distributed storage database based on micro service framework

QLite 是基于微服务的 NewSQL 型数据库系统,与传统的一体化数据库不同,该系统将本该内置的多种数据结构(STL)拆分成多个服务模块,每个模块都是独立的一个节点,每个节点都与其主网关进行连接,从而形成分布式存储结构。

A code generator that turns plain old Go services into RPC-enabled (micro)services with robust HTTP APIs.

Frodo is a code generator and runtime library that helps you write RPC-enabled (micro) services and APIs.

Micro is a platform for cloud native development
Micro is a platform for cloud native development

Micro Overview Micro addresses the key requirements for building services in the cloud. It leverages the microservices architecture pattern and provid

goTempM is a full stack Golang microservices sample application built on top of the Micro platform.
goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

Simple and easy go web micro framework
Simple and easy go web micro framework

DotWeb Simple and easy go web micro framework Important: Now need go1.9+ version support, and support go mod. Document: https://www.kancloud.cn/devfee

a microservice framework for rapid development of micro services in Go with rich eco-system
a microservice framework for rapid development of micro services in Go with rich eco-system

中文版README Go-Chassis is a microservice framework for rapid development of microservices in Go. it focus on helping developer to deliver cloud native a

🦄🌈 YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go.
🦄🌈 YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go.

🦄🌈 YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go. Support Nacos ,Consoul ,Etcd ,Eureka ,kubernetes.

Fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework.

fastglue Overview fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework. It

Another excellent micro service framework

xservice [WIP] Another excellent micro service framework Features RESTful API (base on echo/v4) gRPC & gRPC gateway service & Swagger document generat

Go Micro is a standalone framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Comments
  • Graceful stopping doesn't work.

    Graceful stopping doesn't work.

    Tried graceful stopping with waitgroups. Couldn't get it to work. There is no good example showing how to create the waitgroups for graceful to work as well. Seems like a bug at this point.

    Below, I'm accepting some signals. Then moment I send the signal, my grpc server stops. It prints a message of consul deregistration and it stops.

    main.go ->

            CONSUL_ADDRESS := os.Getenv("CONSUL_ADDRESS")
    	registry := consul.NewRegistry(registry.Addrs(CONSUL_ADDRESS))
    
    	service := micro.NewService(
    		micro.Name("user-module"),
    		micro.Registry(registry),
    		micro.RegisterInterval(time.Second*10),
    	)
    	wg := &sync.WaitGroup{}
    	wg.Add(6)
    	// Register handlers for endpoints
    	go proto.RegisterBHandler(service.Server(), new(handler.CustomBHandler))
    
    	go proto.RegisterFHandler(service.Server(), new(handler.CustomFHandler))
    
    	go proto.RegisterIHandler(service.Server(), new(handler.CustomIHandler))
    
    	go proto.RegisterIHandler(service.Server(), new(handler.CustomPHandler))
    
    	go proto.RegisterUHandler(service.Server(), new(handler.CustomUHandler))
    
    	go proto.RegisterFHandler(service.Server(), new(handler.CustomFHandler))
    
    	// Start server
    	handler.RegisterHTTPServer(&service, wg)
    

    RegisterHTTPServer ->

    func RegisterHTTPServer(service *micro.Service, wg *sync.WaitGroup) {
    
    	r := mux.NewRouter()
    
    	ctx := utils.GetGlobalCtx()
    
    	r.HandleFunc("/health/live", HealthHandler)
    
    	cfg := config.Get().HttpServer
    	addr := fmt.Sprintf("%s:%s", cfg.Addr, cfg.Port)
    
    	ctx.Log().Infof("Starting the  MUX server at  %s", addr)
    
    	srv := &http.Server{
    		Handler: r,
    		Addr:    addr,
    		// Good practice: enforce timeouts for servers you create!
    		WriteTimeout: 15 * time.Second,
    		ReadTimeout:  15 * time.Second,
    	}
    	go func() {
    		(*service).Server().Init(
    			server.Wait(wg),
    		)
    		if err := (*service).Run(); err != nil {
    			ctx.Log().Error(err)
    		}
    	}()
    
    	// start the server
    	go func() {
    		err := srv.ListenAndServe()
    		if err != http.ErrServerClosed {
    			ctx.Log().Errorf("Error starting server: %s\n", err)
    			os.Exit(1)
    		}
    	}()
    
    	// trap sigterm or interupt and gracefully shutdown the server
    	c := make(chan os.Signal, 1)
    	signal.Notify(c,
    		os.Interrupt,
    		// os.Kill, // SIGKILL cannot be caught by application, that's meant to be kill signal, keeping it here so that we know this behavior
    		syscall.SIGTERM,
    		syscall.SIGHUP,
    		syscall.SIGINT,
    		syscall.SIGTERM,
    		syscall.SIGQUIT,
    	)
    
    	// Block until a signal is received.
    	sig := <-c
    	ctx.Log().Warningln("Got signal:", sig)
    
    	// gracefully shutdown the server, waiting max 30 seconds for current operations to complete
    	cancelContext, cancelFunc := context.WithTimeout(context.Background(), 30*time.Second)
    	defer cancelFunc()
    	// srv.Shutdown(cancelContext)
    }
    

    using go micro v3.

    "github.com/asim/go-micro/v3"
    "github.com/asim/go-micro/v3/server"
    
    opened by dibyajyotiron 3
  • pubsub example does not work

    pubsub example does not work

    func (s *Sub) Process(ctx context.Context, event *proto.Event) error {
    	md, _ := metadata.FromContext(ctx)
    	log.Logf("[pubsub.1] Received event %+v with metadata %+v\n", event, md)
    	// do something with event
    	return nil
    }
    
    // Alternatively a function can be used
    func subEv(ctx context.Context, event *proto.Event) error {
    	md, _ := metadata.FromContext(ctx)
    	log.Logf("[pubsub.2] Received event %+v with metadata %+v\n", event, md)
    	// do something with event
    	return nil
    }
    

    in this demo, the handler function of subscribe topic used a pointer parameter, it will cause an panic error: "file=server/rpc_router.go:512 level=error panic recovered: reflect.Value.Addr of unaddressable value".

    I tried use value parameter to fix and it works.

    opened by yyzcode 0
  • Call service error No connection could be made because the target machine actively refused it.

    Call service error No connection could be made because the target machine actively refused it.

    I use go-micro v4.9.0 to build server and client program in greeter. When I run them, the client output {"id":"go.micro.client","code":500,"detail":"connection` error: dial tcp 10.0.0.1:64147: connectex: No connection could be made because the target machine actively refused it.","status":"Internal Server Error"} Who can tell me how to solve it, thanks.

    opened by bravetree 0
  • go.mod error

    go.mod error

    I got the error: github.com/stretchr/testify/assert: github.com/asim/go-micro/plugins/client/grpc/[email protected] (replaced by ../plugins/client/grpc): reading ..\plugins\client\grpc\go.mod: open \path\to\plugins \client\grpc\go.mod: The system cannot find the path specified.

    The solution is: download the plugin repo and add "v4" in the replace position of examples go.mod, like:

    github.com/asim/go-micro/plugins/client/grpc/v4 => ../plugins/v4/client/grpc, not github.com/asim/go-micro/plugins/client/grpc/v4 => ../plugins/client/grpc

    opened by Joseph516 2
Owner
Go Micro
The Go Micro Community
Go Micro
Code examples for Algorithm Analysis and design (CS311) [School project]

Introduction Algorithm Analysis and design 2021/2022 Code examples implemeneted using golang Why Golang? Low Level programming language Awesome garbag

Mohammad Salah 0 Dec 5, 2021
Several Examples for building docker containers for your Go applications

go-docker Several Examples for building docker containers for your Go applicatio

Eric Calabretta 0 Dec 27, 2021
Basic usage of Vecty framework examples.

vecty-examples Basic usage of Vecty framework examples. Instructions Change directory to the folder with the example you wish to run Run wasmserve. To

Patricio Whittingslow 1 Jun 20, 2022
CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser

CONTRIBUTIONS ONLY What does this mean? I do not have time to fix issues myself. The only way fixes or new features will be added is by people submitt

Alec Thomas 3.3k Dec 4, 2022
Generate spreadsheets based on GitHub contributions

pullsheet generates a CSV (comma separated values) & HTML output about GitHub activity across a series of repositories.

Google 63 Oct 17, 2022
A CLI tool queries the GitHub GraphQL API for users and ranks them according to number of contributions

Project homepage Most Active GitHub Users Counter This CLI tool queries the GitHub GraphQL API for users and ranks them according to number of contrib

Mike Owino 0 Dec 6, 2021
null 42 Nov 29, 2022
Sample full stack micro services application built using the go-Micro framework.

goTemp goTemp is a full stack Golang microservices sample application built using go-micro. The application is built as a series of services that prov

null 63 Oct 18, 2022
crud is a cobra based CLI utility which helps in scaffolding a simple go based micro-service along with build scripts, api documentation, micro-service documentation and k8s deployment manifests

crud crud is a CLI utility which helps in scaffolding a simple go based micro-service along with build scripts, api documentation, micro-service docum

Piyush Jajoo 0 Nov 29, 2021
Welcome to the future of programming languages: OK?

OK? Try it out on the playground OK?'s mascot: Quentyn Questionmark. Programming Is Simple Again OK? is a modern, dynamically typed programming langua

Jesse Duffield 421 Dec 7, 2022