Skip to content

Commit 10f6343

Browse files
authored
Merge pull request #71 from beclab/hz_thrift
feat: hertz-thrift recons: all apis replaced
2 parents e7ab9b2 + c8505bd commit 10f6343

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2341
-335
lines changed

.github/workflows/update-server.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,45 @@ jobs:
6262
- name: Build
6363
run: |
6464
go mod tidy
65-
cd cmd/backend
6665
for GOOS in linux; do
6766
for GOARCH in amd64 arm64; do
6867
export GOOS=$GOOS
6968
export GOARCH=$GOARCH
69+
70+
export GOPATH=~/go
71+
export PATH=$GOPATH/bin:$PATH
72+
go install github.com/cloudwego/hertz/cmd/hz@latest
73+
hz -v
74+
GO111MODULE=on go install github.com/cloudwego/thriftgo@latest
75+
76+
go mod tidy
77+
go mod edit -replace github.com/apache/thrift=github.com/apache/[email protected]
78+
go mod tidy
79+
80+
cd pkg/hertz
81+
echo "callback.thrift"
82+
hz update -idl idl/callback.thrift
83+
echo "api thrifts"
84+
hz update -idl idl/external.thrift
85+
hz update -idl idl/md5.thrift
86+
hz update -idl idl/nodes.thrift
87+
hz update -idl idl/paste.thrift
88+
hz update -idl idl/permission.thrift
89+
hz update -idl idl/preview.thrift
90+
hz update -idl idl/raw.thrift
91+
hz update -idl idl/repos.thrift
92+
hz update -idl idl/resources.thrift
93+
hz update -idl idl/tree.thrift
94+
echo "upload.thrift"
95+
hz update -idl idl/upload.thrift
96+
97+
cd ../..
98+
go mod tidy
99+
cd cmd/backend
70100
go build -o filebrowser main.go
71101
mkdir -p dist/$GOOS-$GOARCH
72102
mv filebrowser dist/$GOOS-$GOARCH/
103+
cd ../..
73104
done
74105
done
75106

cmd/backend/app/root.go

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,33 @@ package app
22

33
import (
44
"context"
5-
"crypto/tls"
65
"errors"
76
"files/pkg/common"
7+
"files/pkg/diskcache"
88
"files/pkg/drivers"
99
"files/pkg/drivers/clouds/rclone"
1010
"files/pkg/drivers/sync/seahub/seaserv"
1111
"files/pkg/global"
12+
"files/pkg/hertz"
13+
"files/pkg/img"
1214
"files/pkg/integration"
1315
"files/pkg/postgres"
1416
"files/pkg/redisutils"
1517
"files/pkg/tasks"
1618
"files/pkg/watchers"
19+
"github.com/spf13/afero"
20+
"gopkg.in/natefinch/lumberjack.v2"
1721
"io"
22+
"k8s.io/klog/v2"
1823
"net"
19-
"net/http"
2024
"os"
21-
"os/signal"
22-
"path/filepath"
2325
"strings"
24-
"syscall"
25-
26-
"gopkg.in/natefinch/lumberjack.v2"
27-
"k8s.io/klog/v2"
28-
29-
"files/pkg/diskcache"
3026

3127
homedir "github.com/mitchellh/go-homedir"
32-
"github.com/spf13/afero"
3328
"github.com/spf13/cobra"
3429
"github.com/spf13/pflag"
3530
v "github.com/spf13/viper"
3631

37-
fbhttp "files/pkg/http"
38-
"files/pkg/img"
39-
4032
appsv1 "k8s.io/api/apps/v1"
4133
corev1 "k8s.io/api/core/v1"
4234
ctrl "sigs.k8s.io/controller-runtime"
@@ -147,92 +139,47 @@ user created with the credentials from options "username" and "password".`,
147139
if workersCount < 1 {
148140
klog.Fatal("Image resize workers count could not be < 1")
149141
}
150-
imgSvc := img.New(workersCount) // init global image service
142+
img.New(workersCount) // init global image service
151143

152144
// Step3-2: Build file cache
153-
var fileCache diskcache.Interface = diskcache.NewNoOp()
154-
fileCache = diskcache.New(afero.NewOsFs(), common.CACHE_PREFIX)
145+
diskcache.New(afero.NewOsFs(), common.CACHE_PREFIX)
155146

156147
// step4: Crontab
157148
// - CleanupOldFilesAndRedisEntries
158149
InitCrontabs()
159150

160-
// step5: run http server
161-
server := getRunParams(cmd.Flags())
162-
setupLog(server.Log)
163-
164-
root, err := filepath.Abs(server.Root)
165-
checkErr(err)
166-
server.Root = root
167-
168-
adr := server.Address + ":" + server.Port
169-
170-
var listener net.Listener
171-
172-
switch {
173-
case server.Socket != "":
174-
listener, err = net.Listen("unix", server.Socket)
175-
checkErr(err)
176-
socketPerm, err := cmd.Flags().GetUint32("socket-perm")
177-
checkErr(err)
178-
err = os.Chmod(server.Socket, os.FileMode(socketPerm))
179-
checkErr(err)
180-
case server.TLSKey != "" && server.TLSCert != "":
181-
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey)
182-
checkErr(err)
183-
listener, err = tls.Listen("tcp", adr, &tls.Config{
184-
MinVersion: tls.VersionTLS12,
185-
Certificates: []tls.Certificate{cer}},
186-
)
187-
checkErr(err)
188-
default:
189-
listener, err = net.Listen("tcp", adr)
190-
checkErr(err)
191-
}
192-
193-
// step6: init commands
151+
// step5: init commands
194152
rclone.NewCommandRclone()
195153
rclone.Command.InitServes()
196154

197-
// step7: build driver handler
155+
// step6: build driver handler
198156
drivers.NewDriverHandler()
199157

200-
// step8: init global
158+
// step7: init global
201159
config := ctrl.GetConfigOrDie()
202160
global.InitGlobalData(config)
203161
global.InitGlobalNodes(config)
204162
global.InitGlobalMounted()
205163

206-
// step9: init seahub (for test now)
164+
// step8: init seahub (for test now)
207165
seaserv.InitSeaRPC()
208166

209-
// step10: integration
167+
// step9: integration
210168
integration.NewIntegrationManager()
211169

212-
// step11: watcher
170+
// step10: watcher
213171
var w = watchers.NewWatchers(context.Background(), config)
214172
watchers.AddToWatchers[corev1.Node](w, global.NodeGVR, global.GlobalNode.Handlerevent())
215173
watchers.AddToWatchers[appsv1.StatefulSet](w, appsv1.SchemeGroupVersion.WithResource("statefulsets"), global.GlobalData.HandlerEvent())
216174
watchers.AddToWatchers[integration.User](w, integration.UserGVR, integration.IntegrationManager().HandlerEvent())
217175

218176
go w.Run(1)
219177

220-
// step12: task manager
178+
// step11: task manager
221179
tasks.NewTaskManager()
222180

223-
sigc := make(chan os.Signal, 1)
224-
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
225-
go cleanupHandler(listener, sigc)
226-
227-
handler, err := fbhttp.NewHandler(imgSvc, fileCache, server)
228-
checkErr(err)
229-
230-
defer listener.Close()
231-
232-
klog.Infoln("Listening on", listener.Addr().String())
233-
if err := http.Serve(listener, handler); err != nil {
234-
klog.Fatal(err)
235-
}
181+
// step12: run hertz server
182+
hertz.HertzServer()
236183
}, pythonConfig{allowNoDB: true}),
237184
}
238185

go.mod

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ toolchain go1.23.3
77
replace bytetrade.io/web3os/fs-lib => github.com/beclab/fs-lib v0.0.2
88

99
require (
10-
bytetrade.io/web3os/fs-lib v0.0.0-00010101000000-000000000000
1110
github.com/alitto/pond/v2 v2.3.2
11+
github.com/apache/thrift v0.22.0
1212
github.com/chai2010/tiff v0.0.0-20211005095045-4ec2aa243943
13+
github.com/cloudwego/hertz v0.10.2
1314
github.com/disintegration/imaging v1.6.2
1415
github.com/dsoprea/go-exif/v3 v3.0.1
1516
github.com/emicklei/go-restful/v3 v3.11.0
1617
github.com/fsnotify/fsnotify v1.7.0
17-
github.com/gin-gonic/gin v1.10.0
1818
github.com/go-playground/assert/v2 v2.2.0
1919
github.com/go-redis/redis v6.15.9+incompatible
2020
github.com/go-resty/resty/v2 v2.3.0
@@ -46,31 +46,27 @@ require (
4646
)
4747

4848
require (
49-
github.com/Microsoft/go-winio v0.4.16 // indirect
5049
github.com/beorn7/perks v1.0.1 // indirect
51-
github.com/bytedance/sonic v1.11.6 // indirect
52-
github.com/bytedance/sonic/loader v0.1.1 // indirect
50+
github.com/bytedance/gopkg v0.1.1 // indirect
51+
github.com/bytedance/sonic v1.14.0 // indirect
52+
github.com/bytedance/sonic/loader v0.3.0 // indirect
5353
github.com/cespare/xxhash/v2 v2.3.0 // indirect
54-
github.com/cloudwego/base64x v0.1.4 // indirect
55-
github.com/cloudwego/iasm v0.2.0 // indirect
54+
github.com/cloudwego/base64x v0.1.5 // indirect
55+
github.com/cloudwego/gopkg v0.1.4 // indirect
56+
github.com/cloudwego/netpoll v0.7.0 // indirect
5657
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5758
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
5859
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
5960
github.com/ebitengine/purego v0.8.4 // indirect
61+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
6062
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
6163
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
62-
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
63-
github.com/gin-contrib/sse v0.1.0 // indirect
6464
github.com/go-errors/errors v1.4.2 // indirect
6565
github.com/go-logr/logr v1.4.2 // indirect
6666
github.com/go-ole/go-ole v1.2.6 // indirect
6767
github.com/go-openapi/jsonpointer v0.21.0 // indirect
6868
github.com/go-openapi/jsonreference v0.20.2 // indirect
6969
github.com/go-openapi/swag v0.23.0 // indirect
70-
github.com/go-playground/locales v0.14.1 // indirect
71-
github.com/go-playground/universal-translator v0.18.1 // indirect
72-
github.com/go-playground/validator/v10 v10.20.0 // indirect
73-
github.com/goccy/go-json v0.10.2 // indirect
7470
github.com/gogo/protobuf v1.3.2 // indirect
7571
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
7672
github.com/golang/protobuf v1.5.4 // indirect
@@ -85,20 +81,18 @@ require (
8581
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
8682
github.com/jackc/pgx/v5 v5.5.5 // indirect
8783
github.com/jackc/puddle/v2 v2.2.1 // indirect
88-
github.com/james-barrow/golang-ipc v1.0.0 // indirect
8984
github.com/jinzhu/inflection v1.0.0 // indirect
9085
github.com/jinzhu/now v1.1.5 // indirect
9186
github.com/josharian/intern v1.0.0 // indirect
9287
github.com/json-iterator/go v1.1.12 // indirect
93-
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
94-
github.com/leodido/go-urn v1.4.0 // indirect
88+
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
9589
github.com/magiconair/properties v1.8.7 // indirect
9690
github.com/mailru/easyjson v0.7.7 // indirect
97-
github.com/mattn/go-isatty v0.0.20 // indirect
9891
github.com/mitchellh/mapstructure v1.5.0 // indirect
9992
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
10093
github.com/modern-go/reflect2 v1.0.2 // indirect
10194
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
95+
github.com/nyaruka/phonenumbers v1.0.55 // indirect
10296
github.com/onsi/ginkgo v1.16.5 // indirect
10397
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
10498
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
@@ -108,16 +102,17 @@ require (
108102
github.com/prometheus/procfs v0.15.1 // indirect
109103
github.com/sagikazarmark/locafero v0.4.0 // indirect
110104
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
111-
github.com/smallnest/goframe v1.0.0 // indirect
112105
github.com/sourcegraph/conc v0.3.0 // indirect
113106
github.com/spf13/cast v1.6.0 // indirect
114107
github.com/subosito/gotenv v1.6.0 // indirect
108+
github.com/tidwall/gjson v1.14.4 // indirect
109+
github.com/tidwall/match v1.1.1 // indirect
110+
github.com/tidwall/pretty v1.2.0 // indirect
115111
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
116-
github.com/ugorji/go/codec v1.2.12 // indirect
117112
github.com/x448/float16 v0.8.4 // indirect
118113
github.com/yusufpapurcu/wmi v1.2.4 // indirect
119114
go.uber.org/multierr v1.11.0 // indirect
120-
golang.org/x/arch v0.8.0 // indirect
115+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
121116
golang.org/x/crypto v0.32.0 // indirect
122117
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
123118
golang.org/x/net v0.33.0 // indirect
@@ -140,3 +135,5 @@ require (
140135
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
141136
sigs.k8s.io/yaml v1.4.0 // indirect
142137
)
138+
139+
replace github.com/apache/thrift => github.com/apache/thrift v0.13.0

0 commit comments

Comments
 (0)