MCPcopy Index your code
hub / github.com/2YSP/ship-gate

github.com/2YSP/ship-gate @v2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0 ↗ · + Follow
950 symbols 2,295 edges 131 files 143 documented · 15% updated 3y agov2.0 · 2023-06-20★ 173
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

High Performance,Responsive API Gateways

中文版

Description

This is a high Performance,Responsive API Gateway based on SpringWebFlux and Netty.

Now it only supports HTTP protocol forward,it is for learning communication only.

Project structure

  • Ship-admin: gateway management console,supports config route rule etc.
  • Ship-server: gateway server,core function module.
  • Ship-ship-client-spring-boot-starter: gateway client,automatically register service information to the registration center.
  • Ship-gate-example: an example of how to use the gateway
  • Ship-common: some common codes,like pojo,constants,tools etc.

Features

  • Support custom your own plugins
  • Support A/B test and grayscale publishing
  • Support multiple load balancing strategies
  • Support HTTP protocol,include GET,PUT,POST etc.
  • Support version-based dynamic routing rules
  • Support interface authentication (not implemented)
  • Support cluster deployment
  • Support service rate limit by using Sentinel

Usage

1.nacos

You can refer to this(https://nacos.io/en-us/docs/quick-start.html) to install the nacos.

2.create db

Use the ship.sql in the project to create database first.

3. ship-admin

You need change some config in application.yml.

config item Must Desc
server.port Yes Ship-admin start port
spring.datasource.* Yes Db config
nacos.discovery.server-addr Yes address of nacos

then start the ship-admin,the login address of management backend is http://localhost:9001/user/login/page ,default account admin/1234.

4. backend project

New a springboot project and dependency in pom.xml.

 <dependency>
            <groupId>cn.sp</groupId>
            <artifactId>ship-client-spring-boot-starter</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

Next change some config in application.yml.

config item Must Desc
nacos.discovery.server-addr Yes address of nacos
ship.http.app-name Yes your app name of backend project,eg: order,the context-path is same with app-name
ship.http.version Yes version of app,eg:gray_1.0
ship.http.port Yes the port of project,same with sever.port
ship.http.admin-url Yes the url of ship-admin,eg: 127.0.0.1:9001

If you think it's trouble,you can just use the ship-gate-example for test.

5. ship-server

It's most important part of ship-gate,similarly you must config some option.

config item Must Option value Desc
nacos.discovery.server-addr Yes address of nacos
ship.gate.load-balance No random,round,weightRound load balance algorithm,default round
ship.gate.time-out-millis No time out millis of gateway,default 3000ms
ship.gate.cache-refresh-interval No default 10s

Finally start ship-sever and just have fun!

Architecture diagram

网关设计

Prerequisite

  • JDK1.8+

  • MySQL

  • Nacos 1.3+

If you want to know more details or have any question,please click here or contact me in time.

Extension points exported contracts — how you extend this code

LoadBalance (Interface)
Created by 2YSP on 2020/12/27 [6 implementers]
ship-server/src/main/java/cn/sp/spi/LoadBalance.java
UserService (Interface)
@Author: Ship @Description: @Date: Created in 2021/1/4 [3 implementers]
ship-admin/src/main/java/cn/sp/service/UserService.java
ShipPlugin (Interface)
@Author: Ship @Description: @Date: Created in 2020/12/25 [5 implementers]
ship-server/src/main/java/cn/sp/plugin/ShipPlugin.java
RuleService (Interface)
@Author: Ship @Description: @Date: Created in 2020/12/28 [2 implementers]
ship-admin/src/main/java/cn/sp/service/RuleService.java
AppService (Interface)
@Author: Ship @Description: @Date: Created in 2020/12/24 [2 implementers]
ship-admin/src/main/java/cn/sp/service/AppService.java
AppInstanceService (Interface)
@Author: Ship @Description: @Date: Created in 2021/1/5 [2 implementers]
ship-admin/src/main/java/cn/sp/service/AppInstanceService.java
AppMapper (Interface)
Created by 2YSP on 2020/12/23
ship-admin/src/main/java/cn/sp/mapper/AppMapper.java

Core symbols most depended-on inside this repo

test
called by 359
ship-gate-example/src/main/java/cn/sp/controller/UserController.java
i
called by 153
ship-admin/src/main/resources/static/layui/layui.all.js
t
called by 141
ship-admin/src/main/resources/static/layui/layui.all.js
i
called by 133
ship-admin/src/main/resources/static/layui/lay/modules/form.js
t
called by 112
ship-admin/src/main/resources/static/layui/lay/modules/layer.js
w
called by 93
ship-admin/src/main/resources/static/layui/layui.all.js
w
called by 88
ship-admin/src/main/resources/static/layui/lay/modules/laydate.js
match
called by 81
ship-common/src/main/java/cn/sp/utils/StringTools.java

Shape

Method 489
Function 350
Class 88
Interface 17
Enum 6

Languages

Java63%
TypeScript37%

Modules by API surface

ship-admin/src/main/resources/static/admin/js/jquery.js78 symbols
ship-admin/src/main/resources/static/layui/layui.all.js66 symbols
ship-admin/src/main/resources/static/layui/lay/modules/jquery.js66 symbols
ship-admin/src/main/java/cn/sp/pojo/vo/RuleVO.java27 symbols
ship-admin/src/main/resources/static/layui/lay/modules/mobile.js24 symbols
ship-admin/src/main/java/cn/sp/bean/RouteRule.java23 symbols
ship-common/src/main/java/cn/sp/pojo/dto/AppRuleDTO.java19 symbols
ship-admin/src/main/java/cn/sp/pojo/RuleDTO.java19 symbols
ship-admin/src/main/resources/static/layui/lay/modules/layedit.js15 symbols
ship-admin/src/main/java/cn/sp/pojo/vo/InstanceVO.java15 symbols
ship-admin/src/main/java/cn/sp/pojo/vo/AppVO.java15 symbols
ship-admin/src/main/java/cn/sp/bean/AppInstance.java15 symbols

Datastores touched

(mysql)Database · 1 repos
shipDatabase · 1 repos

For agents

$ claude mcp add ship-gate \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact