Skip to content

Commit

Permalink
feat:优化目录结构并格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
yomea committed Mar 8, 2024
1 parent dfaaa45 commit 7bec74d
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 126 deletions.
35 changes: 18 additions & 17 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
# hangu-gateway

#### Description

网关

#### Software Architecture

Software architecture description

#### Installation

1. xxxx
2. xxxx
3. xxxx
1. xxxx
2. xxxx
3. xxxx

#### Instructions

1. xxxx
2. xxxx
3. xxxx
1. xxxx
2. xxxx
3. xxxx

#### Contribution

1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request

1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request

#### Gitee Feature

1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# hangu-gateway

#### 介绍

网关,支持通过 http 调用 hangu-rpc

6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.hangu</groupId>
<groupId>org.hangu.gateway</groupId>
<artifactId>hangu-gateway</artifactId>
<version>1.0-SNAPSHOT</version>

Expand Down Expand Up @@ -32,7 +32,7 @@
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<groupId>org.hangu</groupId>
<groupId>org.hangu.rpc</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>

Expand Down Expand Up @@ -121,7 +121,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.hangu.Bootstrap</mainClass>
<mainClass>org.hangu.gateway.Bootstrap</mainClass>
</manifest>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.hangu;
package org.hangu.gateway;

import com.hangu.common.properties.HanguProperties;
import com.hangu.common.properties.ZookeeperConfigProperties;
import com.hangu.common.registry.RegistryService;
import com.hangu.common.registry.ZookeeperRegistryService;
import com.hangu.rpc.common.properties.HanguProperties;
import com.hangu.rpc.common.properties.ZookeeperConfigProperties;
import com.hangu.rpc.common.registry.RegistryService;
import com.hangu.rpc.common.registry.ZookeeperRegistryService;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.hangu.server.NettyServer;
import org.hangu.gateway.server.NettyServer;

/**
* @author wuzhenhong
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.hangu.constant;
package org.hangu.gateway.constant;

import io.netty.handler.codec.http.HttpHeaderValues;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.hangu.handler;
package org.hangu.gateway.handler;

/**
* 网关配置
*
* @author wuzhenhong
* @date 2023/8/9 14:10
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.hangu.handler;

import com.hangu.common.entity.HttpServletRequest;
import com.hangu.common.entity.HttpServletResponse;
import com.hangu.common.exception.RpcInvokerException;
import com.hangu.common.properties.ExecutorProperties;
import com.hangu.common.properties.HanguProperties;
import com.hangu.common.registry.RegistryService;
import com.hangu.consumer.http.HttpGenericProxyFactory;
import com.hangu.consumer.http.HttpGenericService;
package org.hangu.gateway.handler;

import com.hangu.rpc.common.entity.HttpServletRequest;
import com.hangu.rpc.common.entity.HttpServletResponse;
import com.hangu.rpc.common.exception.RpcInvokerException;
import com.hangu.rpc.common.properties.ExecutorProperties;
import com.hangu.rpc.common.properties.HanguProperties;
import com.hangu.rpc.common.registry.RegistryService;
import com.hangu.rpc.consumer.http.HttpGenericProxyFactory;
import com.hangu.rpc.consumer.http.HttpGenericService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
Expand All @@ -25,7 +25,7 @@
import java.util.Optional;
import java.util.concurrent.Executor;
import lombok.extern.slf4j.Slf4j;
import org.hangu.constant.CommonCons;
import org.hangu.gateway.constant.CommonCons;

/**
* @author wuzhenhong
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.hangu.server;
package org.hangu.gateway.server;

import com.hangu.common.properties.HanguProperties;
import com.hangu.common.registry.RegistryService;
import com.hangu.rpc.common.properties.HanguProperties;
import com.hangu.rpc.common.registry.RegistryService;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelInitializer;
Expand All @@ -18,8 +18,8 @@
import java.util.Objects;
import java.util.concurrent.Executor;
import lombok.extern.slf4j.Slf4j;
import org.hangu.constant.CommonCons;
import org.hangu.handler.NettyHttpServerHandler;
import org.hangu.gateway.constant.CommonCons;
import org.hangu.gateway.handler.NettyHttpServerHandler;

/**
* @author wuzhenhong
Expand All @@ -28,7 +28,8 @@
@Slf4j
public class NettyServer {

public static void start(int port, Executor executor, RegistryService registryService, HanguProperties hanguProperties) {
public static void start(int port, Executor executor, RegistryService registryService,
HanguProperties hanguProperties) {

NioEventLoopGroup boss = new NioEventLoopGroup();
NioEventLoopGroup worker = new NioEventLoopGroup(CommonCons.DEF_IO_THREADS);
Expand All @@ -54,13 +55,14 @@ protected void initChannel(SocketChannel ch) {
// 解决大码流的问题,ChunkedWriteHandler:向客户端发送HTML5文件
.addLast("http-chunked", new ChunkedWriteHandler())
// 自定义处理handler
.addLast("http-server", new NettyHttpServerHandler(executor, registryService, hanguProperties));
.addLast("http-server",
new NettyHttpServerHandler(executor, registryService, hanguProperties));
}
});
serverBootstrap.bind(port).sync().addListener(future -> {
if (!future.isSuccess()) {
Throwable cause = future.cause();
if(Objects.nonNull(cause)) {
if (Objects.nonNull(cause)) {
log.error("服务启动失败---》绑定失败!!!", cause);
} else {
log.error("服务启动失败---》绑定失败!!!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.hangu.utils;
package org.hangu.gateway.utils;

import java.io.FileInputStream;
import java.io.InputStream;
Expand All @@ -8,7 +8,7 @@
import java.util.List;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
import org.hangu.constant.CommonCons;
import org.hangu.gateway.constant.CommonCons;

/**
* @author wuzhenhong
Expand Down Expand Up @@ -49,7 +49,9 @@ public static Properties loadProperties(String fileName) {
input.close();
}
} catch (Throwable e) {
log.warn("Failed to load " + fileName + " file from " + fileName + "(ingore this file): " + e.getMessage(), e);
log.warn(
"Failed to load " + fileName + " file from " + fileName + "(ingore this file): " + e.getMessage(),
e);
}
return properties;
}
Expand All @@ -66,14 +68,14 @@ public static Properties loadProperties(String fileName) {
log.warn("Fail to load " + fileName + " file: " + t.getMessage(), t);
}

if(list.size() == 0) {
if (list.size() == 0) {
log.warn("No " + fileName + " found on the class path.");
return properties;
}

log.info("load " + fileName + " properties file from " + list);

for(java.net.URL url : list) {
for (java.net.URL url : list) {
try {
Properties p = new Properties();
InputStream input = url.openStream();
Expand All @@ -84,7 +86,8 @@ public static Properties loadProperties(String fileName) {
} finally {
try {
input.close();
} catch (Throwable t) {}
} catch (Throwable t) {
}
}
}
} catch (Throwable e) {
Expand Down
Loading

0 comments on commit 7bec74d

Please sign in to comment.