All Projects → gmsec → gmsec

gmsec / gmsec

Licence: Apache-2.0 license
golang micro service base on gin. golang 微服务集成框架

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to gmsec

Cinema
使用 go-micro 微服务框架开发的电影院订票系统
Stars: ✭ 140 (-0.71%)
Mutual labels:  gin, go-micro
go2sky-plugins
The plugins of go2sky
Stars: ✭ 46 (-67.38%)
Mutual labels:  gin, go-micro
short
URL shortening service. 高性能短链接服务。
Stars: ✭ 14 (-90.07%)
Mutual labels:  gin, go-micro
cookiecutter-go
boilerplate, golang project starter tool, support go-zero/go-micro/gin
Stars: ✭ 63 (-55.32%)
Mutual labels:  gin, go-micro
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (+5.67%)
Mutual labels:  gin
MicroServicePractice
微服务实践的demo
Stars: ✭ 40 (-71.63%)
Mutual labels:  go-micro
grpc-todo
A TODO app using grpc-web and Vue.js
Stars: ✭ 76 (-46.1%)
Mutual labels:  gin
server-benchmarks
🚀 Cross-platform transparent benchmarks for HTTP/2 Web Servers at 2020-2023
Stars: ✭ 78 (-44.68%)
Mutual labels:  gin
pink-lady
a template project of gin app.
Stars: ✭ 44 (-68.79%)
Mutual labels:  gin
goblog
使用golang写的个人博客mirrored from https://gitlab.com/xiayesuifeng/goblog.git
Stars: ✭ 26 (-81.56%)
Mutual labels:  gin
go-gin-logrus
Gin Web Framework for using Logrus as the Gin logger with Tracing middleware
Stars: ✭ 38 (-73.05%)
Mutual labels:  gin
go-rest
Build golang restful api, with - Gin Framework and MongoDB
Stars: ✭ 20 (-85.82%)
Mutual labels:  gin
ginhelper
gin framework helper
Stars: ✭ 16 (-88.65%)
Mutual labels:  gin
requestid
Request ID middleware for Gin Framework
Stars: ✭ 115 (-18.44%)
Mutual labels:  gin
advanced-cloud-native-go
Advanced Cloud Native Go - Packt Publishing Video Course
Stars: ✭ 18 (-87.23%)
Mutual labels:  go-micro
httpsign
Signing HTTP Messages Middleware
Stars: ✭ 54 (-61.7%)
Mutual labels:  gin
gin-cache
🚀 A high performance gin middleware to cache http response. Compared to gin-contrib/cache, It has a huge performance improvement. 高性能gin缓存中间件,相比于官方版本,有巨大性能提升。
Stars: ✭ 151 (+7.09%)
Mutual labels:  gin
web-marisa
🍄 白丝魔理沙网页版
Stars: ✭ 65 (-53.9%)
Mutual labels:  gin
goroseGin
gorose + gin demo,半小时快速上手golang web编程之用户的增删改查(示例代码)
Stars: ✭ 18 (-87.23%)
Mutual labels:  gin
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (-9.93%)
Mutual labels:  gin

Build Status Go Report Card codecov GoDoc

gmsec

特点

  • 打通grpc + gin,同时支持grpc 跟 restful 模式
  • grpc , gin 公用端口
  • gorm 嵌入,自动数据库代码生成

golang 微服务集成框架

安装

  • install

  • proto环境安装

 make install 
  • 本地环境搭建(gmsec为例)
make gen
  • 新建一个服务
make new service=[服务名]

proto定义

syntax = "proto3"; // 指定proto版本
package proto;     // 指定包名
option go_package = ".;proto"; // 指定路径

// 定义Hello服务
service Hello {
    // 定义SayHello方法
    rpc SayHello(HelloRequest) returns (HelloReply) {}
}
// HelloRequest 请求结构
message HelloRequest {
    string name = 1; // 名字
}
// HelloReply 响应结构
message HelloReply {
    string message = 1; // 消息
}

服务端代码示例

package main

import (
	"context"
	"fmt"
	proto "gmsec/rpc/gmsec"

	"github.com/gmsec/goplugins/api"
	"github.com/gin-gonic/gin"
	"github.com/gmsec/goplugins/plugin"
	"github.com/gmsec/micro"
	"github.com/xxjwxc/ginrpc"
)

func main() {
	// grpc 相关 初始化服务
	service := micro.NewService(
		micro.WithName("lp.srv.eg1"),
	)
	h := new(hello)
	proto.RegisterHelloServer(service.Server(), h) // 服务注册
	// ----------- end

	// gin 相关
	base := ginrpc.New(ginrpc.WithCtx(api.NewAPIFunc), ginrpc.WithDebug(dev.IsDev()))
	router := gin.Default()
	v1 := router.Group("/xxjwxc/api/v1")
	base.Register(v1, h) // 对象注册
	// ------ end

	plg, _ := plugin.Run(plugin.WithMicro(service),// grpc 入口
		plugin.WithGin(router), // http 入口
        plugin.WithAddr(":8080")) // 开始服务(公用端口)
    
	plg.Wait() // 等待结束(ctrl+c)
    
	fmt.Println("done")
}

// Ctx gin.Context 到 context.Context 的转换
func Ctx(c *gin.Context) interface{} {
	return context.Background()
}

客户端代码:

package main

import (
	"context"
	"fmt"
	proto "gmsec/rpc/gmsec"

	"github.com/gmsec/micro"
)

func main() {
    // reg := registry.NewDNSNamingRegistry()
	// grpc 相关 注册服务发现等
	micro.NewService(
        micro.WithName("lp.srv.eg1"),
        // micro.WithRegisterTTL(time.Second*30),      //指定服务注册时间
        // micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册
        // micro.WithRegistryNaming(reg),
	)
	// ----------- end

	say := proto.GetHelloClient()
	ctx := context.Background()
	resp, _ := say.SayHello(ctx, &proto.HelloRequest{Name:"xxjwxc"})
	fmt.Println("result:", resp)
}

更多示例 => 传送门

正在做

  • etcdv3

传送门

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].