一款依赖 etcd 作为注册中心的 Golang 轻量级 GRPC 框架

Golang 微服务 GRPC 标准框架(轻量级)

特性介绍

  1. 可使用 etcd 集群或单节点作为注册中心
  2. 客户端请求服务端自带负载均衡
  3. 服务端启动后自动向 etcd 注册,默认每 10s 进行一次心跳续租
  4. 自带优雅停止
  5. panic recover
  6. 服务端无需指定启动端口,当然你也可以通过 WithPort() 自行设置

使用说明

一、依赖说明

该框架依赖 etcd 因此你需要自行安装 etcd,并且在目录configs/common/etcd.toml 中进行配置

配置内容如下

[etcd]
host = "127.0.0.1"
port = 2379

你可以使用docker安装etcd单节点进行测试

安装命令如下

export HostIP=0.0.0.0
docker run -itd --rm \
  -p 2379:2379 \
  -p 2380:2380 \
  --volume=/etcd-data:/etcd-data \
  --name etcd quay.io/coreos/etcd:latest \
  /usr/local/bin/etcd \
  --data-dir=/etcd-data --name node1 \
  --initial-advertise-peer-urls http://${HostIP}:2380 --listen-peer-urls http://${HostIP}:2380 \
  --advertise-client-urls http://${HostIP}:2379 --listen-client-urls http://${HostIP}:2379 \
  --initial-cluster node1=http://${HostIP}:2380

进入容器测试命令

etcdctl --endpoints=http://${HostIP}:2379 member list

二、protobuf 使用说明

如果你是用来测试,以下内容可以略过,直接编译运行 example 目录下的 serverclient即可。

命令:

go build server.go
go build client.go

但如若你需要进行开发,请自行安装 protobuf 编译工具

安装方法如下

1. protoc

下载地址:https://github.com/protocolbuffers/protobuf/releases

2.安装 gogofaster 插件

go get github.com/gogo/protobuf/protoc-gen-gogofaster

3.生成代码

编写在 proto 目录下编写代码,使用一下命令生成

protoc --gogofaster_out=plugins=grpc:. ./目录地址/*

并将生成的文件拖动至 gen 目录下,做到编码规范

结语

如果您喜欢该项目,请给个 star 吧

作者:兰陵美酒郁金香

Owner
兰陵美酒郁金香丶❀
苟且偷生的 Golang 工程师
兰陵美酒郁金香丶❀
Similar Resources

Go gRPC RabbitMQ email microservice

Go, RabbitMQ and gRPC Clean Architecture microservice 👋 👨‍💻 Full list what has been used: GRPC - gRPC RabbitMQ - RabbitMQ sqlx - Extensions to data

Dec 29, 2022

Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.

Sample cloud-native application with 10 microservices showcasing Kubernetes, Istio, gRPC and OpenCensus.

Online Boutique is a cloud-native microservices demo application. Online Boutique consists of a 10-tier microservices application. The application is

Dec 31, 2022

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

Aug 22, 2022

drpc is a lightweight, drop-in replacement for gRPC

drpc is a lightweight, drop-in replacement for gRPC

drpc is a lightweight, drop-in replacement for gRPC

Jan 8, 2023

Go microservices with REST, and gRPC using BFF pattern.

Go microservices with REST, and gRPC using BFF pattern.

Go microservices with REST, and gRPC using BFF pattern. This repository contains backend services. Everything is dockerized and ready to

Jan 4, 2023

A gRPC API for Warhammer Age of Sigmar

Warhammer 🔥 A gRPC API for Warhammer Age of Sigmar Intro ℹ️ Skip to Quick Start What is this? An API for creating, reading, deleting, and updating a

Oct 26, 2021

Just a quick demo of how you can use automatically generated protobuffer and gRPC code from buf.build

buf.build demo The purpose of this repository is to demonstrate how to use the services offered by buf.build for hosting protobuffer definitions and a

Jan 4, 2022

Jaeger-s3 - Jaeger gRPC storage plugin for Amazon S3

jaeger-s3 jaeger-s3 is gRPC storage plugin for Jaeger, which uses Amazon Kinesis

Dec 26, 2022

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

#1 Golang live reload and task runner Content - ⭐️ Top Features - 💃🏻 Get started - 📄 Config sample - 📚 Commands List - 🛠 Support and Suggestions

Dec 31, 2022
Golang 微服务框架,支持 grpc/http,支持多种注册中心 etcd,consul,mdns 等

一个用于构建分布式系统的工具集或者轻框架,支持 grpc 和 http ,支持多种注册中心 consul ,etcd , mdns 等。

Nov 30, 2022
gRPC to JSON proxy generator following the gRPC HTTP spec
gRPC to JSON proxy generator following the gRPC HTTP spec

The gRPC-Gateway is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC. This server is generated according to the google.api.http annotations in your service definitions.

Jan 3, 2023
微服务架构-micro-基于go-zero zrpc etcd 单独集成orm-gorm 日志-uber/zap

micro目录结构 pkg ├── api 业务接口逻辑层 所有的业务逻辑存放目录。 │ ├── model 数据模型 数据管理层,仅用于操作管理数据,如数据库操作 ├── assets

Jul 12, 2022
An instance of go-micro with etcd

go-micro_with_etcd_instance An instance of go-micro with etcd。最新版go-micro用Etcd做服

Mar 10, 2022
Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported
Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported

Go Microservice Starter A boilerplate for flexible Go microservice. Table of contents Features Installation Todo List Folder Structures Features: Mult

Jul 28, 2022
Testing ground for CRUD backend using Golang, gRPC, protobufs

blog-example-service Simple example CRUD backend using Golang, gRPC, and protobufs. Using with MongoDB as the database (default) You will need a Mongo

Dec 16, 2021
Golang Microservice making use of protobuf and gRPC as the underlying transport protocol.

Go-Microservices Golang Microservice making use of protobuf and gRPC as the underlying transport protocol. I will be building a generic microservice,

Jan 5, 2022
Authentication-microservice - Microservice for user authentication built with golang and gRPC

Authentication-microservice - Microservice for user authentication built with golang and gRPC

May 30, 2022
Article - Golang mysql rest grpc

To bring up the project run: To bring up database on docker in root folder run:

Sep 26, 2022
Customer-microservice - Microservice of customer built with golang and gRPC

?? Building microservices to manage customer data using Go and gRPC Command to g

Sep 8, 2022