mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
25w27a
This commit is contained in:
parent
dcc50401c4
commit
8a50b311fc
7 changed files with 63 additions and 14 deletions
|
|
@ -1,5 +1,12 @@
|
|||
# 更新日志
|
||||
|
||||
25w27a - 2025-04-07
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v3.0.1的预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 加入`memLimit`指示gc
|
||||
- CHANGE: 加入`hlog`输出路径配置
|
||||
- CHANGE: 修正H2C配置问题
|
||||
|
||||
3.0.0 - 2025-04-04
|
||||
---
|
||||
- RELEASE: Next Gen; 下一个起点;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
25w26a
|
||||
25w27a
|
||||
|
|
@ -32,6 +32,7 @@ type ServerConfig struct {
|
|||
Port int `toml:"port"`
|
||||
Host string `toml:"host"`
|
||||
SizeLimit int `toml:"sizeLimit"`
|
||||
MemLimit int64 `toml:"memLimit"`
|
||||
H2C bool `toml:"H2C"`
|
||||
Cors string `toml:"cors"`
|
||||
Debug bool `toml:"debug"`
|
||||
|
|
@ -89,6 +90,7 @@ type LogConfig struct {
|
|||
LogFilePath string `toml:"logFilePath"`
|
||||
MaxLogSize int `toml:"maxLogSize"`
|
||||
Level string `toml:"level"`
|
||||
HertZLogPath string `toml:"hertzLogPath"`
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -179,6 +181,7 @@ func DefaultConfig() *Config {
|
|||
Port: 8080,
|
||||
Host: "0.0.0.0",
|
||||
SizeLimit: 125,
|
||||
MemLimit: 0,
|
||||
H2C: true,
|
||||
Cors: "*",
|
||||
Debug: false,
|
||||
|
|
@ -207,6 +210,7 @@ func DefaultConfig() *Config {
|
|||
LogFilePath: "/data/ghproxy/log/ghproxy.log",
|
||||
MaxLogSize: 10,
|
||||
Level: "info",
|
||||
HertZLogPath: "/data/ghproxy/log/hertz.log",
|
||||
},
|
||||
Auth: AuthConfig{
|
||||
Enabled: false,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
host = "0.0.0.0"
|
||||
port = 8080
|
||||
sizeLimit = 125 # MB
|
||||
memLimit = 0 # MB
|
||||
H2C = true
|
||||
cors = "*" # "*"/"" -> "*" ; "nil" -> "" ;
|
||||
debug = false
|
||||
|
|
@ -30,6 +31,7 @@ staticDir = "/data/www"
|
|||
logFilePath = "/data/ghproxy/log/ghproxy.log"
|
||||
maxLogSize = 5 # MB
|
||||
level = "info" # dump, debug, info, warn, error, none
|
||||
hertzLogPath = "/data/ghproxy/log/hertz.log"
|
||||
|
||||
[auth]
|
||||
method = "parameters" # "header" or "parameters"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
host = "127.0.0.1"
|
||||
port = 8080
|
||||
sizeLimit = 125 # MB
|
||||
memLimit = 0 # MB
|
||||
H2C = true
|
||||
cors = "*" # "*"/"" -> "*" ; "nil" -> "" ;
|
||||
debug = false
|
||||
|
|
@ -30,6 +31,7 @@ staticDir = "/usr/local/ghproxy/pages"
|
|||
logFilePath = "/usr/local/ghproxy/log/ghproxy.log"
|
||||
maxLogSize = 5 # MB
|
||||
level = "info" # dump, debug, info, warn, error, none
|
||||
hertzLogPath = "/usr/local/ghproxy/log/hertz.log"
|
||||
|
||||
[auth]
|
||||
authMethod = "parameters" # "header" or "parameters"
|
||||
|
|
|
|||
39
main.go
39
main.go
|
|
@ -8,6 +8,7 @@ import (
|
|||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"ghproxy/api"
|
||||
|
|
@ -23,6 +24,7 @@ import (
|
|||
"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
"github.com/cloudwego/hertz/pkg/common/adaptor"
|
||||
"github.com/cloudwego/hertz/pkg/common/hlog"
|
||||
|
||||
"github.com/hertz-contrib/http2/factory"
|
||||
)
|
||||
|
|
@ -31,6 +33,7 @@ var (
|
|||
cfg *config.Config
|
||||
r *server.Hertz
|
||||
configfile = "/data/ghproxy/config/config.toml"
|
||||
hertZfile *os.File
|
||||
cfgfile string
|
||||
version string
|
||||
runMode string
|
||||
|
|
@ -129,7 +132,29 @@ func setupLogger(cfg *config.Config) {
|
|||
fmt.Printf("Log Level: %s\n", cfg.Log.Level)
|
||||
logDebug("Config File Path: ", cfgfile)
|
||||
logDebug("Loaded config: %v\n", cfg)
|
||||
logInfo("Init Completed")
|
||||
logInfo("Logger Initialized Successfully")
|
||||
}
|
||||
|
||||
func setupHertZLogger(cfg *config.Config) {
|
||||
var err error
|
||||
|
||||
if cfg.Log.HertZLogPath != "" {
|
||||
hertZfile, err = os.OpenFile(cfg.Log.HertZLogPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to open log file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
hlog.SetOutput(hertZfile)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func setMemLimit(cfg *config.Config) {
|
||||
if cfg.Server.MemLimit > 0 {
|
||||
debug.SetMemoryLimit((cfg.Server.MemLimit) * 1024 * 1024)
|
||||
logInfo("Set Memory Limit to %d MB", cfg.Server.MemLimit)
|
||||
}
|
||||
}
|
||||
|
||||
func loadlist(cfg *config.Config) {
|
||||
|
|
@ -315,7 +340,9 @@ func init() {
|
|||
loadConfig()
|
||||
if cfg != nil { // 在setupLogger前添加空值检查
|
||||
setupLogger(cfg)
|
||||
setupHertZLogger(cfg)
|
||||
InitReq(cfg)
|
||||
setMemLimit(cfg)
|
||||
loadlist(cfg)
|
||||
setupRateLimit(cfg)
|
||||
|
||||
|
|
@ -346,12 +373,17 @@ func main() {
|
|||
|
||||
addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
||||
|
||||
r := server.New(
|
||||
if cfg.Server.H2C {
|
||||
r = server.New(
|
||||
server.WithHostPorts(addr),
|
||||
server.WithH2C(true),
|
||||
)
|
||||
|
||||
r.AddProtocol("h2", factory.NewServerFactory())
|
||||
} else {
|
||||
r = server.New(
|
||||
server.WithHostPorts(addr),
|
||||
)
|
||||
}
|
||||
|
||||
// 添加Recovery中间件
|
||||
r.Use(recovery.Recovery())
|
||||
|
|
@ -414,5 +446,6 @@ func main() {
|
|||
|
||||
r.Spin()
|
||||
defer logger.Close()
|
||||
defer hertZfile.Close()
|
||||
fmt.Println("Program Exit")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
|
|||
// 错误处理(404)
|
||||
if resp.StatusCode == 404 {
|
||||
c.String(http.StatusNotFound, "File Not Found")
|
||||
//c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue