micro_gateway

command module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Micro Gateway

🧱一个高性能微服务网关

Micro Gateway 管理后台Demo

demo1 demo2 demo3

✨功能

功能脑图

🔧技术栈

后端

  • Golang
  • Gin
  • Gorm
  • Redis
  • MySql
  • Swagger
  • Docker

前端

  • Vue.js
  • Vue-element-admin

🚀快速开始

  • Golang版本要求Golang1.12+
  • 下载类库依赖
export GO111MODULE=on && export GOPROXY=https://goproxy.cn
cd mirco_gateway
go mod tidy
  • 创建数据库并导入
mysql -h localhost -u root -p -e "CREATE DATABASE mirco_gateway DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql -h localhost -u root -p mirco_gateway < gateway.sql --default-character-set=utf8

后端部署

直接运行
make build_dev
sh run.sh
使用Docker部署
  • 部署网关管理服务
docker run --name dashboard --net host -e TZ=Asia/Shanghai -d dockerfile-dashboard:latest
  • 部署代理服务
docker run --name gateway_server --net host -e TZ=Asia/Shanghai -d dockerfile-server:latest

Dashboard部署

  • 方式一: Dashboard前端与后端服务分开部署
    • 在vue.config.js文件中设置publicPath为/
    • 在.env.production文件中设置VUE_APP_BASE_API为自己需要的url前缀,本项目设置为/prod-api。
    • 编译。
    npm run build:prod
    
    • 通过nginx代理实现与后端接口服务的同域访问。
     server {
          listen       8884;
          server_name  localhost;
          root /dashboard编译生成的结果的路径;
          index  index.html index.htm index.php;
    
          location / {
              try_files $uri $uri/ /index.html?$args;
          }
    
          location /prod-api/ {
              proxy_pass http://127.0.0.1:8880/; #后端服务接口
          }
    }
    
    • 访问http://你的ip:8884即可。
  • 方式二:与后端项目合并部署。
    • 在vue.config.js文件中设置publicPath为/dist
    • 在.env.production文件中设置VUE_APP_BASE_API为空。
    • 在后端项目的router包的route.go文件中增加代码
    router.Static("/dist", "./dist")
    
    • 编译后放入到后端项目的根目录下。
    • 访问http://后端IP:后端port/dist

测试

  • example目录为模拟下游服务节点的代码。

代理规则

  • HTTP/HTTPS代理:通过HttpRule.Rule字段以前缀匹配的形式实现不同下游服务的转发
  • TCP代理:通过TcpRule.Port字段实现不同tcp服务的转发
  • GRPC代理:通过GrpcRule.Port字段实现不同GRPC服务的转发

💻API文档

生成接口文档:swag init
然后启动服务器:go run main.go,浏览地址: http://127.0.0.1:8880/swagger/index.html

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Code generated by swaggo/swag.
Code generated by swaggo/swag.
example
grpc_real_server/proto
Package proto is a reverse proxy.
Package proto is a reverse proxy.
grpc_real_server/server command
Binary server is an example server.
Binary server is an example server.
http_real_server command
模拟实际的下游节点
模拟实际的下游节点
tcp_real_server command
internal
dao
dto
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址