Giter Site home page Giter Site logo

cocainecong / micro-todolist Goto Github PK

View Code? Open in Web Editor NEW
136.0 3.0 45.0 341 KB

Go语言微服务实战,go-micro+gin+gorm+rabbitMQ 构造简单备忘录,包括ETCD作为服务发现,JWT鉴权,降级熔断等等

License: MIT License

Go 97.99% Makefile 2.01%
etcd gin go go-micro golang gorm hystrix microservice mysql rabbitmq

micro-todolist's Introduction

micro-todoList

Go-Micro V4 + RabbitMQ 构造简单备忘录

将原项目的micro的v2升到v4,服务发现使用etcd,支持熔断机制,token验证,网关和各模块之间的rpc通信等

项目的详细博客地址

用户模块

备忘录模块

项目的视频介绍地址

Go-Micro+RabbitMQ 构建简单备忘录

项目的主要功能介绍

  • 用户注册登录 ( jwt-go鉴权 )
  • 新增/删除/修改/查询 备忘录

项目主要依赖:

Golang V1.18

  • Gin
  • Gorm
  • mysql
  • go-micro
  • protobuf
  • grpc
  • amqp
  • ini
  • hystrix
  • jwt-go
  • crypto

项目结构

1.micro_todolist 项目总体

micro-todolist/
├── app                   // 各个微服务
│   ├── gateway           // 网关
│   ├── task              // 任务模块微服务
│   └── user              // 用户模块微服务
├── bin                   // 编译后的二进制文件模块
├── config                // 配置文件
├── consts                // 定义的常量
├── doc                   // 接口文档
├── idl                   // protoc文件
│   └── pb                // 放置生成的pb文件
├── logs                  // 放置打印日志模块
├── pkg                   // 各种包
│   ├── ctl               // 用户操作
│   ├── e                 // 统一错误状态码
│   ├── logger            // 日志
│   └── util              // 各种工具、JWT等等..
└── types                 // 定义各种结构体

2.gateway 网关部分

gateway/
├── cmd                   // 启动入口
├── http                  // HTTP请求头
├── handler               // 视图层
├── logs                  // 放置打印日志模块
├── middleware            // 中间件
├── router                // http 路由模块
├── rpc                   // rpc 调用
└── wrappers              // 熔断

3.user && task 用户与任务模块

task/
├── cmd                   // 启动入口
├── service               // 业务服务
├── repository            // 持久层
│    ├── db               // 视图层
│    │    ├── dao         // 对数据库进行操作
│    │    └── model       // 定义数据库的模型
│    └── mq               // 放置 mq
├── script                // 监听 mq 的脚本
└── service               // 服务

config/config.ini文件,直接将 config.ini.example-->config.ini 就可以了 conf/config.ini 文件

[service]
AppMode = debug
HttpPort = :4000

[mysql]
Db = mysql
DbHost = 127.0.0.1
DbPort = 3306
DbUser = micro_todolist
DbPassWord = micro_todolist
DbName = micro_todolist
Charset = utf8mb4

[rabbitmq]
RabbitMQ = amqp
RabbitMQUser = guest
RabbitMQPassWord = guest
RabbitMQHost = localhost
RabbitMQPort = 5672

[etcd]
EtcdHost = localhost
EtcdPort = 2379

[server]
UserServiceAddress = 127.0.0.1:8082
TaskServiceAddress = 127.0.0.1:8083

[redis]
RedisHost = localhost
RedisPort = 6379
RedisPassword = micro_todolist

运行简要说明

  1. 启动环境
make env-up
  1. 运行服务
make run

注意:

  1. 保证rabbitMQ开启状态
  2. 保证etcd开启状态
  3. 依次执行各模块下的main.go文件

如果出错一定要注意打开etcd的keeper查看服务是否注册到etcd中!!

导入接口文档

打开postman,点击导入

postman导入

选择导入文件 选择导入接口文件

导入

效果

postman

micro-todolist's People

Contributors

3927o avatar cocainecong avatar fleezesd avatar fodesu avatar palp1tate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

micro-todolist's Issues

JWT UserInfo 缓存问题

作者这里的的缓存 InitUserInfo() 方法有问题吧

如果用 user_key 作为缓存的 key :

  1. 第二帐户登录的时候,缓存会覆盖。
  2. 如果这时候,第一个帐户的 token没有过期,然后在 task 中调用 GetUserInfo() , 拿到的是第二个用户的信息。

var userKey string = "user_key"
type UserInfo struct {
Id uint `json:"id"`
}
func InitUserInfo(ctx context.Context, user *UserInfo) error {
cachedUser, err := GetUserInfo(ctx)
if err != nil {
return err
}
// 如果缓存中存在用户信息,直接返回
if cachedUser != nil {
return nil
}
// 如果缓存中不存在用户信息,将用户信息存储到缓存中
if err := SetUserInCache(ctx, user, cache.RedisClient); err != nil {
return err
}
return nil
}

通道问题

在app/task/repository/mq/task文件下的task_sync.go 中关于forever通道只使用了var声明,而最后直接取值,这部分有问题吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.