Skip to content

Commit 6a48858

Browse files
committed
重构和修复命令行参数解析
1 parent 1a45296 commit 6a48858

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

cmd/gateway-proxy/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var (
1919

2020
// 初始化方法
2121
func init() {
22+
flag.Parse()
23+
2224
config.InitConf(*configPath, *debugMode)
2325
config.NewLogger()
2426
config.NewMySql()
@@ -28,14 +30,12 @@ func init() {
2830
}
2931

3032
func main() {
31-
flag.Parse()
32-
3333
appConfig := config.GetAppConfig()
3434

3535
httpServer := &server.HttpServer{
3636
Server: &http.Server{
3737
Addr: fmt.Sprintf(":%d", appConfig.Server.Port),
38-
Handler: router.Handler(),
38+
Handler: router.WebHandler(),
3939
},
4040
}
4141

internal/logic/limit/LimitLogic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func checkLimit(cacheKey string, limit int, intervalTime int) (int, bool) {
3434
return 0, true
3535
}
3636

37-
count, timeMillis := redis.GetAccessTotal(cacheKey)
37+
count, timeMillis := redis.GetAccessTotalAndTimeMillis(cacheKey)
3838

3939
diffTime := date.GetCurrentTimeMillis() - timeMillis
4040
intervalMillis := int64(intervalTime * 1000)

internal/logic/redis/RedisLogic.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func GetAccessTotalCacheKey(routeId int, code string) string {
1818
return fmt.Sprintf("%s:%s:%d", config.GetAppConfig().AppName, code, routeId)
1919
}
2020

21-
// GetAccessTotal 访问数量增加一次
22-
func GetAccessTotal(cacheKey string) (int, int64) {
21+
// GetAccessTotalAndTimeMillis 获取访问总数和计数时间
22+
func GetAccessTotalAndTimeMillis(cacheKey string) (int, int64) {
2323
cache, err := config.Redis().Get(cacheKey).Result()
2424
if nil != err || 0 == len(cache) {
2525
return 0, date.GetCurrentTimeMillis()

internal/router/Router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func buildRoutes() []routeInfo {
4242
return routePath
4343
}
4444

45-
func Handler() http.HandlerFunc {
45+
func WebHandler() http.HandlerFunc {
4646
routePath := buildRoutes()
4747
return func(rspWriter http.ResponseWriter, request *http.Request) {
4848
for _, route := range routePath {

0 commit comments

Comments
 (0)