Skip to content

Commit 509106e

Browse files
committed
fix: 格式化代码
1 parent e1c43fe commit 509106e

File tree

12 files changed

+57
-21
lines changed

12 files changed

+57
-21
lines changed

src/main/java/love/wangqi/GatewayServerDemo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ protected List<Route> locateRouteList(Set<Long> ids) {
3232
List<Route> routeList = new ArrayList<>();
3333
try {
3434
routeList.add(new Route(1L, HttpMethod.GET, "/", new URL("https://blog.wangqi.love/")));
35+
routeList.add(new Route(1L, HttpMethod.GET, "/wangqi", new URL("http://wangqi.love/")));
36+
routeList.add(new Route(1L, HttpMethod.GET, "/117", new URL("http://10.0.111.117/#/login")));
3537
routeList.add(new Route(2L, HttpMethod.GET, "/baidu", new URL("https://www.baidu.com/")));
36-
routeList.add(new Route(3L, HttpMethod.GET, "/taobao", new URL("https://www.taobao.com/")));
38+
routeList.add(new Route(3L, HttpMethod.GET, "/taobao", new URL("http://www.taobao.com/")));
3739
routeList.add(new Route(4L, HttpMethod.GET, "/github", new URL("https://github.com/")));
3840
routeList.add(new Route(5L, HttpMethod.GET, "/oschina", new URL("https://www.oschina.net/")));
3941
routeList.add(new Route(6L, HttpMethod.POST, "/users/{id}", new URL("http://127.0.0.1/pre/users/{id}")));

src/main/java/love/wangqi/codec/DefaultHttpRequestBuilder.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public RequestHolder build(FullHttpRequest originRequest) throws Exception {
5656
if (route == null) {
5757
throw new GatewayNoRouteException();
5858
}
59-
URL url = route.getMapUrl();
59+
URL url = route.getMapUrl();
6060
logger.info("proxy_pass {}", url.toString());
6161

6262
// 请求路径
@@ -80,7 +80,7 @@ public RequestHolder build(FullHttpRequest originRequest) throws Exception {
8080
if (contentType.startsWith(HttpHeaderValues.APPLICATION_JSON.toString())) {
8181
ByteBuf bbuf = Unpooled.copiedBuffer(buildContentJson(route), StandardCharsets.UTF_8);
8282
newRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, bbuf.readableBytes());
83-
((FullHttpRequest)newRequest).content().writeBytes(bbuf);
83+
((FullHttpRequest) newRequest).content().writeBytes(bbuf);
8484
} else if (contentType.startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString())) {
8585
HttpPostRequestEncoder requestEncoder = new HttpPostRequestEncoder(newRequest, false);
8686
buildContentFormUrlEncoded(route).forEach((key, values) -> {
@@ -107,14 +107,15 @@ public RequestHolder build(FullHttpRequest originRequest) throws Exception {
107107
} else {
108108
ByteBuf byteBuf = buildContentOther(route);
109109
newRequest.headers().set(HttpHeaderNames.CONTENT_LENGTH, byteBuf.readableBytes());
110-
((FullHttpRequest)newRequest).content().writeBytes(byteBuf);
110+
((FullHttpRequest) newRequest).content().writeBytes(byteBuf);
111111
}
112112
}
113113
return new RequestHolder(route, url, newRequest, newBodyRequestEncoder);
114114
}
115115

116116
/**
117117
* 返回path(不包含?后面的参数部分)
118+
*
118119
* @return
119120
*/
120121
protected String buildPath(Route route) {
@@ -123,6 +124,7 @@ protected String buildPath(Route route) {
123124

124125
/**
125126
* 返回请求的请求参数
127+
*
126128
* @return
127129
*/
128130
protected Map<String, List<String>> buildParams(Route route) {
@@ -131,6 +133,7 @@ protected Map<String, List<String>> buildParams(Route route) {
131133

132134
/**
133135
* 返回请求的请求头
136+
*
134137
* @return
135138
*/
136139
protected Map<String, List<String>> buildHeaders(Route route) {
@@ -139,6 +142,7 @@ protected Map<String, List<String>> buildHeaders(Route route) {
139142

140143
/**
141144
* 如果content-type为application/json,获取请求体
145+
*
142146
* @return
143147
*/
144148
protected String buildContentJson(Route route) {
@@ -147,6 +151,7 @@ protected String buildContentJson(Route route) {
147151

148152
/**
149153
* 如果content-type为application/x-www-form-urlencoded,获取请求体
154+
*
150155
* @return
151156
*/
152157
protected Map<String, List<String>> buildContentFormUrlEncoded(Route route) {
@@ -155,6 +160,7 @@ protected Map<String, List<String>> buildContentFormUrlEncoded(Route route) {
155160

156161
/**
157162
* 如果content-type为multipart/form-data,获取请求体
163+
*
158164
* @return
159165
*/
160166
protected List<InterfaceHttpData> buildContentFormData(Route route) {
@@ -163,6 +169,7 @@ protected List<InterfaceHttpData> buildContentFormData(Route route) {
163169

164170
/**
165171
* 其他类型的content-type则直接返回相应的ByteBuf
172+
*
166173
* @return
167174
*/
168175
private ByteBuf buildContentOther(Route route) {

src/main/java/love/wangqi/codec/HttpRequestBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
public interface HttpRequestBuilder {
1414
/**
1515
* 设置路由映射器
16+
*
1617
* @param routeMapper
1718
* @return
1819
*/
1920
HttpRequestBuilder setRouteMapper(RouteMapper routeMapper);
2021

2122
/**
2223
* 生成新的请求
24+
*
2325
* @param originRequest
2426
* @return
2527
* @throws Exception
@@ -28,6 +30,7 @@ public interface HttpRequestBuilder {
2830

2931
/**
3032
* 获取路由
33+
*
3134
* @param originRequest
3235
* @return
3336
*/

src/main/java/love/wangqi/codec/HttpRequestDecomposer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public HttpRequestDecomposer(FullHttpRequest request) {
3232

3333
/**
3434
* 获取请求的uri(包含?后面的参数部分)
35+
*
3536
* @return
3637
*/
3738
public String getUri() {
@@ -40,6 +41,7 @@ public String getUri() {
4041

4142
/**
4243
* 获取请求路径(不包含?后面的参数部分)
44+
*
4345
* @return
4446
*/
4547
public String getPath() {
@@ -49,6 +51,7 @@ public String getPath() {
4951

5052
/**
5153
* 获取请求参数
54+
*
5255
* @return
5356
*/
5457
public Map<String, List<String>> getParams() {
@@ -58,6 +61,7 @@ public Map<String, List<String>> getParams() {
5861

5962
/**
6063
* 获取content-type
64+
*
6165
* @return
6266
*/
6367
public String getContentType() {
@@ -66,6 +70,7 @@ public String getContentType() {
6670

6771
/**
6872
* 获取请求头
73+
*
6974
* @return
7075
*/
7176
public Map<String, List<String>> getHeaders() {
@@ -87,6 +92,7 @@ public Map<String, List<String>> getHeaders() {
8792

8893
/**
8994
* 如果content-type为application/json,将内容转换成JsonNode
95+
*
9096
* @return
9197
*/
9298
public JsonNode getContentJson() {
@@ -95,6 +101,7 @@ public JsonNode getContentJson() {
95101

96102
/**
97103
* 如果content-type为application/json,以字符串形式返回请求体
104+
*
98105
* @return
99106
*/
100107
public String getContentJsonAsString() {
@@ -103,6 +110,7 @@ public String getContentJsonAsString() {
103110

104111
/**
105112
* 如果content-type为application/json,将内容转换成相应的类型
113+
*
106114
* @return
107115
*/
108116
public <T> T getContentJson(Class<T> valueType) {
@@ -117,6 +125,7 @@ public <T> T getContentJson(Class<T> valueType) {
117125

118126
/**
119127
* 如果content-type为application/x-www-form-urlencoded,将内容转换成map
128+
*
120129
* @return
121130
*/
122131
public Map<String, List<String>> getContentFormUrlEncoded() {
@@ -127,6 +136,7 @@ public Map<String, List<String>> getContentFormUrlEncoded() {
127136

128137
/**
129138
* 如果content-type为multipart/form-data,获取内容列表
139+
*
130140
* @return
131141
*/
132142
public List<InterfaceHttpData> getContentFormdata() {
@@ -136,6 +146,7 @@ public List<InterfaceHttpData> getContentFormdata() {
136146

137147
/**
138148
* 其他类型的content-type则直接返回相应的ByteBuf
149+
*
139150
* @return
140151
*/
141152
public ByteBuf getContentOther() {
@@ -144,6 +155,7 @@ public ByteBuf getContentOther() {
144155

145156
/**
146157
* 以字符串形式返回请求体
158+
*
147159
* @return
148160
*/
149161
public String getContentAsString() {

src/main/java/love/wangqi/exception/handler/ExceptionHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
public interface ExceptionHandler {
1111
/**
1212
* 获取异常返回
13+
*
1314
* @param exception
1415
* @return
1516
*/
1617
ExceptionResponse getExceptionResponse(Exception exception);
1718

1819
/**
1920
* 发送异常
21+
*
2022
* @param channel
2123
* @param exceptionResponse
2224
*/
2325
void send(Channel channel, ExceptionResponse exceptionResponse);
2426

2527
/**
2628
* 处理异常
29+
*
2730
* @param channel
2831
* @param exception
2932
*/

src/main/java/love/wangqi/filter/FilterProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public static FilterProcessor getInstance() {
2222
return INSTANCE;
2323
}
2424

25-
private FilterProcessor() {}
25+
private FilterProcessor() {
26+
}
2627

2728
public void preRoute(Channel channel) throws GatewayException {
2829
try {

src/main/java/love/wangqi/filter/IGatewayFilter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public interface IGatewayFilter {
1111
/**
1212
* 过滤Http请求
13+
*
1314
* @param channel
1415
* @throws Exception
1516
*/

src/main/java/love/wangqi/handler/GatewayRunner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public class GatewayRunner {
2020

2121
private final static GatewayRunner INSTANCE = new GatewayRunner();
2222

23-
private GatewayRunner() {}
23+
private GatewayRunner() {
24+
}
2425

2526
public static GatewayRunner getInstance() {
2627
return INSTANCE;
@@ -53,6 +54,7 @@ public Thread newThread(Runnable r) {
5354

5455
/**
5556
* 线程名称前缀
57+
*
5658
* @return
5759
*/
5860
abstract String getNamePrefix();

src/main/java/love/wangqi/route/AbstractRouteMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract class AbstractRouteMapper implements RouteMapper {
2727

2828
/**
2929
* 遍历所有的路由,返回符合请求的路由
30+
*
3031
* @param path
3132
* @param method
3233
* @return
@@ -74,6 +75,7 @@ public Route getRoute(HttpRequest request) {
7475

7576
/**
7677
* 获取路由列表
78+
*
7779
* @param ids 路由id的列表
7880
* @return
7981
*/

src/main/java/love/wangqi/route/RouteMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public interface RouteMapper {
1515
/**
1616
* 根据路径获取Route
17+
*
1718
* @param path
1819
* @param method
1920
* @return
@@ -22,19 +23,22 @@ public interface RouteMapper {
2223

2324
/**
2425
* 根据请求获取Route
26+
*
2527
* @param request
2628
* @return
2729
*/
2830
Route getRoute(HttpRequest request);
2931

3032
/**
3133
* 刷新路由
34+
*
3235
* @param ids 路由id的列表
3336
*/
3437
void refresh(Set<Long> ids);
3538

3639
/**
3740
* 获取路由列表
41+
*
3842
* @return
3943
*/
4044
List<Route> getRouteList();

0 commit comments

Comments
 (0)