Skip to content

Commit da7ded6

Browse files
authored
Merge pull request #12 from WJQSERVER-STUDIO/dev
1.0.2
2 parents 22ab134 + 3cbf769 commit da7ded6

10 files changed

Lines changed: 129 additions & 100 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# 更新日志
22

3+
1.0.2 - 2025-04-11
4+
---
5+
- ADD: 加入`memLimit`以指示gc
6+
7+
25w05a - 2025-04-07
8+
---
9+
- PRE-RELEASE: 此版本是v1.0.2的预发布版本,请勿在生产环境中使用;
10+
- ADD: 加入`memLimit`以指示gc
11+
312
1.0.1 - 2025-03-28
413
---
514
- CHANGE: 加入`c.SetBodyStream`以流式传输

DEV-VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
25w04c
1+
25w05a

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Docker Compose 安装 [docker-compose.yml](https://github.com/WJQSERVER-STUDIO/s
1919
host = "0.0.0.0" # 监听地址
2020
port = 8080 # 监听端口
2121
baseDir = "/data/smart-git/repos" # 缓存文件夹
22+
memLimit = 0 #MB 内存使用限制
2223

2324
[log]
2425
logfilepath = "/data/smart-git/log/smart-git.log" # 日志存储位置

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.2

config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ type Config struct {
1515
}
1616

1717
type ServerConfig struct {
18-
Host string `toml:"host"`
19-
Port int `toml:"port"`
20-
BaseDir string `toml:"baseDir"`
18+
Host string `toml:"host"`
19+
Port int `toml:"port"`
20+
BaseDir string `toml:"baseDir"`
21+
MemLimit int64 `toml:"memLimit"`
2122
}
2223

2324
type LogConfig struct {

config/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
host = "0.0.0.0"
33
port = 8080
44
baseDir = "/data/smart-git/repos"
5+
memLimit = 0 #MB
56

67
[log]
78
logfilepath = "/data/smart-git/log/smart-git.log"

go.mod

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,41 @@ module smart-git
33
go 1.24.1
44

55
require (
6-
github.com/BurntSushi/toml v1.4.0
7-
github.com/cloudwego/hertz v0.9.6
6+
github.com/BurntSushi/toml v1.5.0
7+
github.com/cloudwego/hertz v0.9.7
88
github.com/go-git/go-billy/v5 v5.6.2
9-
github.com/go-git/go-git/v5 v5.14.0
9+
github.com/go-git/go-git/v5 v5.15.0
1010
github.com/hertz-contrib/gzip v0.0.3
1111
github.com/hertz-contrib/http2 v0.1.8
1212
)
1313

1414
require (
1515
github.com/WJQSERVER-STUDIO/go-utils/log v0.0.1 // indirect
16-
github.com/bytedance/gopkg v0.1.1 // indirect
17-
github.com/bytedance/sonic v1.13.1 // indirect
16+
github.com/bytedance/gopkg v0.1.2 // indirect
17+
github.com/bytedance/sonic v1.13.2 // indirect
1818
github.com/bytedance/sonic/loader v0.2.4 // indirect
1919
github.com/cloudwego/base64x v0.1.5 // indirect
20-
github.com/cloudwego/netpoll v0.6.5 // indirect
21-
github.com/fsnotify/fsnotify v1.8.0 // indirect
20+
github.com/cloudwego/gopkg v0.1.4 // indirect
21+
github.com/cloudwego/netpoll v0.7.0 // indirect
22+
github.com/fsnotify/fsnotify v1.9.0 // indirect
2223
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
23-
github.com/nyaruka/phonenumbers v1.5.0 // indirect
24+
github.com/nyaruka/phonenumbers v1.6.0 // indirect
2425
github.com/tidwall/gjson v1.18.0 // indirect
2526
github.com/tidwall/match v1.1.1 // indirect
2627
github.com/tidwall/pretty v1.2.1 // indirect
2728
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
28-
golang.org/x/arch v0.15.0 // indirect
29-
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
30-
golang.org/x/text v0.23.0 // indirect
31-
google.golang.org/protobuf v1.36.5 // indirect
29+
golang.org/x/arch v0.16.0 // indirect
30+
golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect
31+
golang.org/x/text v0.24.0 // indirect
32+
google.golang.org/protobuf v1.36.6 // indirect
3233
)
3334

3435
require (
3536
dario.cat/mergo v1.0.1 // indirect
3637
github.com/Microsoft/go-winio v0.6.2 // indirect
37-
github.com/ProtonMail/go-crypto v1.1.6 // indirect
38+
github.com/ProtonMail/go-crypto v1.2.0 // indirect
3839
github.com/WJQSERVER-STUDIO/go-utils/logger v1.5.0
39-
github.com/cloudflare/circl v1.6.0 // indirect
40+
github.com/cloudflare/circl v1.6.1 // indirect
4041
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
4142
github.com/emirpasic/gods v1.18.1 // indirect
4243
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
@@ -48,8 +49,8 @@ require (
4849
github.com/skeema/knownhosts v1.3.1 // indirect
4950
github.com/xanzy/ssh-agent v0.3.3 // indirect
5051
go.etcd.io/bbolt v1.4.0
51-
golang.org/x/crypto v0.36.0 // indirect
52-
golang.org/x/net v0.37.0 // indirect
53-
golang.org/x/sys v0.31.0 // indirect
52+
golang.org/x/crypto v0.37.0 // indirect
53+
golang.org/x/net v0.39.0 // indirect
54+
golang.org/x/sys v0.32.0 // indirect
5455
gopkg.in/warnings.v0 v0.1.2 // indirect
5556
)

go.sum

Lines changed: 81 additions & 42 deletions
Large diffs are not rendered by default.

http.go

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import (
1616

1717
"github.com/cloudwego/hertz/pkg/app"
1818
"github.com/cloudwego/hertz/pkg/app/server"
19+
20+
//"github.com/cloudwego/hertz/pkg/network/standard"
1921
"github.com/go-git/go-billy/v5/osfs"
2022
"github.com/go-git/go-git/v5/plumbing"
2123
"github.com/go-git/go-git/v5/plumbing/format/pktline"
2224
"github.com/go-git/go-git/v5/plumbing/protocol/packp"
2325
"github.com/go-git/go-git/v5/plumbing/transport"
2426
gitserver "github.com/go-git/go-git/v5/plumbing/transport/server"
2527

26-
//hresp "github.com/cloudwego/hertz/pkg/protocol/http1/resp"
2728
rgzip "github.com/hertz-contrib/gzip"
2829
"github.com/hertz-contrib/http2/factory"
2930
)
@@ -42,6 +43,8 @@ func RunHTTP(addr string, baseRepoDir string) error {
4243
r := server.New(
4344
server.WithHostPorts(addr),
4445
server.WithH2C(true),
46+
//server.WithALPN(true),
47+
//server.WithTransport(standard.NewTransporter),
4548
)
4649

4750
r.AddProtocol("h2", factory.NewServerFactory())
@@ -174,13 +177,10 @@ func httpInfoRefs(ctx context.Context, c *app.RequestContext, baseRepoDir string
174177
return
175178
}
176179

177-
//c.Response.HijackWriter(hresp.NewChunkedBodyWriter(&c.Response, c.GetWriter()))
178-
179180
ar.Prefix = [][]byte{
180181
[]byte("# service=git-upload-pack"),
181182
pktline.Flush,
182183
}
183-
//writer := c.Response.BodyWriter()
184184

185185
pr, pw := io.Pipe()
186186
go func() {
@@ -198,20 +198,6 @@ func httpInfoRefs(ctx context.Context, c *app.RequestContext, baseRepoDir string
198198
}()
199199

200200
c.SetBodyStream(pr, -1)
201-
202-
/*
203-
204-
err = ar.Encode(writer)
205-
if err != nil {
206-
logError("Error encoding advertised references: %v, repo: %s\n", err, repoName)
207-
_, errResp := c.WriteString(err.Error())
208-
if errResp != nil {
209-
logError("WriteString error: %v\n", errResp)
210-
}
211-
c.Status(http.StatusInternalServerError)
212-
return
213-
}
214-
*/
215201
}
216202

217203
// httpGitUploadPack 函数处理 /git-upload-pack 请求,允许客户端推送代码到服务器。
@@ -314,10 +300,6 @@ func httpGitUploadPack(ctx context.Context, c *app.RequestContext, baseRepoDir s
314300
return
315301
}
316302

317-
//c.Response.HijackWriter(hresp.NewChunkedBodyWriter(&c.Response, c.GetWriter()))
318-
319-
//writer := c.Response.BodyWriter()
320-
321303
pr, pw := io.Pipe()
322304

323305
go func() {
@@ -336,18 +318,4 @@ func httpGitUploadPack(ctx context.Context, c *app.RequestContext, baseRepoDir s
336318
}()
337319

338320
c.SetBodyStream(pr, -1)
339-
340-
/*
341-
err = res.Encode(writer) // 使用 c.Response.BodyWriter() 作为 io.Writer
342-
343-
if err != nil {
344-
logError("Error encoding upload pack result: %v, repo: %s\n", err, repoName)
345-
_, errResp := c.WriteString(err.Error())
346-
if errResp != nil {
347-
logError("WriteString error: %v\n", errResp)
348-
}
349-
c.Status(http.StatusInternalServerError)
350-
return
351-
}
352-
*/
353321
}

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"log"
77
"os"
8+
"runtime/debug"
89
"smart-git/config"
910
"smart-git/database"
1011

@@ -41,10 +42,18 @@ func loadConfig() {
4142
fmt.Printf("Loaded config: %v\n", cfg)
4243
}
4344

45+
func setMemLimit(cfg *config.Config) {
46+
if cfg.Server.MemLimit > 0 {
47+
debug.SetMemoryLimit((cfg.Server.MemLimit) * 1024 * 1024)
48+
logInfo("Set Memory Limit to %d MB", cfg.Server.MemLimit)
49+
}
50+
}
51+
4452
// init
4553
func init() {
4654
ReadFlag()
4755
loadConfig()
56+
setMemLimit(cfg)
4857

4958
// 创建根目录 os
5059
err := os.MkdirAll(cfg.Server.BaseDir, 0755)

0 commit comments

Comments
 (0)