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

stark

Github Actions Go Report Card LICENSE

stark 命名源自漫威 Tony Stark

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

功能

  • 服务发现
  • 负载均衡
  • grpc/http Server 和 Client
  • ...

stark ctl

go get  github.com/Allenxuxu/stark/cmd/stark

查询注册服务

stark service -r consul -rg 127.0.0.1:8500 {service name}

Example

grpc server

rg, err := mdns.NewRegistry()
if err != nil {
    panic(err)
}

s := stark.NewRPCServer(rg,
    rpc.Name("stark.rpc.test"),
    rpc.Version("v0.0.1"),
)

rs := &routeGuideServer{}
pb.RegisterRouteGuideServer(s.GrpcServer(), rs)

if err := s.Start(); err != nil {
    panic(err)
}
cd example/rpc/server
go run main.go

使用 stark 工具 查看已经注册的服务

stark service stark.rpc.test

grpc client

rg, err := mdns.NewRegistry()
if err != nil {
    panic(err)
}

s, err := registry.NewSelector(rg,
    selector.BalancerName(balancer.RoundRobin),
)
if err != nil {
    panic(err)
}

client, err := stark.NewRPCClient("stark.rpc.test", s,
    rpc.GrpcDialOption(
        grpc.WithInsecure(),
    ),
)
if err != nil {
    panic(err)
}

c := routeguide.NewRouteGuideClient(client.Conn())

for i := 0; i < 10; i++ {
    resp, err := c.GetFeature(context.Background(), &routeguide.Point{
        Latitude:  0,
        Longitude: 0,
    })
    if err != nil {
        panic(err)
    }
}

http server

rg, err := mdns.NewRegistry()
if err != nil {
    panic(err)
}

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

s := stark.NewRestServer(rg, r,
    rest.Name("stark.http.test"),
)

if err := s.Start(); err != nil {
    panic(err)
}

http client

rg, err := mdns.NewRegistry()
if err != nil {
    panic(err)
}

s, err := registry.NewSelector(rg)
if err != nil {
    panic(err)
}

c, err := stark.NewRestClient("stark.http.test", s)
if err != nil {
    panic(err)
}

for i := 0; i < 5; i++ {
    r, err := c.Request()
    if err != nil {
        panic(err)
    }

    resp, err := r.Get("/ping")
    if err != nil {
        panic(err)
    }

    log.Info(resp)
}

感谢

go-micro 本项目就是受到 go-micro 的启发而来,本意就是构建一个比 go-micro 更加轻量,够用就好的微服务框架。 项目中 config,registry 都是从 go-micro v1.18 改造而来。

Owner
徐旭
礼法岂是为吾辈而设
徐旭
Similar Resources

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

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
Comments
  • Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0

    Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0

    Bumps github.com/gin-gonic/gin from 1.6.3 to 1.7.0.

    Release notes

    Sourced from github.com/gin-gonic/gin's releases.

    Release v1.7.0

    BUGFIXES

    • fix compile error from #2572 (#2600)
    • fix: print headers without Authorization header on broken pipe (#2528)
    • fix(tree): reassign fullpath when register new node (#2366)

    ENHANCEMENTS

    • Support params and exact routes without creating conflicts (#2663)
    • chore: improve render string performance (#2365)
    • Sync route tree to httprouter latest code (#2368)
    • chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa (#2375)
    • chore(performance): improve countParams (#2378)
    • Remove some functions that have the same effect as the bytes package (#2387)
    • update:SetMode function (#2321)
    • remove a unused type SecureJSONPrefix (#2391)
    • Add a redirect sample for POST method (#2389)
    • Add CustomRecovery builtin middleware (#2322)
    • binding: avoid 2038 problem on 32-bit architectures (#2450)
    • Prevent panic in Context.GetQuery() when there is no Request (#2412)
    • Add GetUint and GetUint64 method on gin.context (#2487)
    • update content-disposition header to MIME-style (#2512)
    • reduce allocs and improve the render WriteString (#2508)
    • implement ".Unwrap() error" on Error type (#2525) (#2526)
    • Allow bind with a map[string]string (#2484)
    • chore: update tree (#2371)
    • Support binding for slice/array obj [Rewrite] (#2302)
    • basic auth: fix timing oracle (#2609)
    • Add mixed param and non-param paths (port of httprouter#329) (#2663)
    • feat(engine): add trustedproxies and remoteIP (#2632)
    Changelog

    Sourced from github.com/gin-gonic/gin's changelog.

    Gin v1.7.0

    BUGFIXES

    • fix compile error from #2572 (#2600)
    • fix: print headers without Authorization header on broken pipe (#2528)
    • fix(tree): reassign fullpath when register new node (#2366)

    ENHANCEMENTS

    • Support params and exact routes without creating conflicts (#2663)
    • chore: improve render string performance (#2365)
    • Sync route tree to httprouter latest code (#2368)
    • chore: rename getQueryCache/getFormCache to initQueryCache/initFormCa (#2375)
    • chore(performance): improve countParams (#2378)
    • Remove some functions that have the same effect as the bytes package (#2387)
    • update:SetMode function (#2321)
    • remove a unused type SecureJSONPrefix (#2391)
    • Add a redirect sample for POST method (#2389)
    • Add CustomRecovery builtin middleware (#2322)
    • binding: avoid 2038 problem on 32-bit architectures (#2450)
    • Prevent panic in Context.GetQuery() when there is no Request (#2412)
    • Add GetUint and GetUint64 method on gin.context (#2487)
    • update content-disposition header to MIME-style (#2512)
    • reduce allocs and improve the render WriteString (#2508)
    • implement ".Unwrap() error" on Error type (#2525) (#2526)
    • Allow bind with a map[string]string (#2484)
    • chore: update tree (#2371)
    • Support binding for slice/array obj [Rewrite] (#2302)
    • basic auth: fix timing oracle (#2609)
    • Add mixed param and non-param paths (port of httprouter#329) (#2663)
    • feat(engine): add trustedproxies and remoteIP (#2632)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

go 微服务框架

goo 微服务框架 HTTP/RPC Rabbitmq/Kafka队列 Redis缓存 事件驱动 日志告警 文件系统 限流熔断降级 链路监控 k8s/istio部署方便 启动步骤 1. 拷贝config.example.toml至config.toml 根据需求修改其内容

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

Golang 微服务 GRPC 标准框架(轻量级) 特性介绍 可使用 etcd 集群或单节点作为注册中心 客户端请求服务端自带负载均衡 服务端启动后自动向 etcd 注册,默认每 10s 进行一次心跳续租 自带优雅停止 panic recover 服务端无需指定启动端口,当然你也可以通过 WithP

Nov 11, 2021
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