Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65986f4

Browse files
authored
Refactor embedded assets and drop unnecessary dependencies (#34692)
Benefits:1. smaller binary size (reduces more than 1MB)2. better control of the assets details3. fewer unmaintained dependencies4. faster startup if the assets are not needed5. won't hang up editors when open "bindata.go" by accident
1 parent18bafcc commit65986f4

24 files changed

+579
-368
lines changed

‎.gitignore‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,10 @@ _testmain.go
4242
coverage.all
4343
cpu.out
4444

45-
/modules/migration/bindata.go
46-
/modules/migration/bindata.go.hash
47-
/modules/options/bindata.go
48-
/modules/options/bindata.go.hash
49-
/modules/public/bindata.go
50-
/modules/public/bindata.go.hash
51-
/modules/templates/bindata.go
52-
/modules/templates/bindata.go.hash
45+
/modules/migration/bindata.*
46+
/modules/options/bindata.*
47+
/modules/public/bindata.*
48+
/modules/templates/bindata.*
5349

5450
*.db
5551
*.log

‎Makefile‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ WEBPACK_CONFIGS := webpack.config.js tailwind.config.js
120120
WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
121121
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts
122122

123-
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
124-
BINDATA_HASH :=$(addsuffix .hash,$(BINDATA_DEST))
123+
BINDATA_DEST := modules/public/bindata.dat modules/options/bindata.dat modules/templates/bindata.dat
125124

126125
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
127126

@@ -149,14 +148,8 @@ SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US
149148
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
150149

151150
GO_SOURCES :=$(wildcard*.go)
152-
GO_SOURCES +=$(shell find$(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
151+
GO_SOURCES +=$(shell find$(GO_DIRS) -type f -name "*.go")
153152
GO_SOURCES +=$(GENERATED_GO_DEST)
154-
GO_SOURCES_NO_BINDATA :=$(GO_SOURCES)
155-
156-
ifeq ($(filter$(TAGS_SPLIT),bindata),bindata)
157-
GO_SOURCES += $(BINDATA_DEST)
158-
GENERATED_GO_DEST += $(BINDATA_DEST)
159-
endif
160153

161154
# Force installation of playwright dependencies by setting this flag
162155
ifdefDEPS_PLAYWRIGHT
@@ -226,7 +219,7 @@ clean-all: clean ## delete backend, frontend and integration files
226219

227220
.PHONY: clean
228221
clean:## delete backend and integration files
229-
rm -rf$(EXECUTABLE)$(DIST)$(BINDATA_DEST)$(BINDATA_HASH)\
222+
rm -rf$(EXECUTABLE)$(DIST)$(BINDATA_DEST)\
230223
integrations*.test\
231224
e2e*.test\
232225
tests/integration/gitea-integration-*\
@@ -268,7 +261,7 @@ endif
268261
.PHONY: generate-swagger
269262
generate-swagger:$(SWAGGER_SPEC)## generate the swagger spec from code comments
270263

271-
$(SWAGGER_SPEC):$(GO_SOURCES_NO_BINDATA)$(SWAGGER_SPEC_INPUT)
264+
$(SWAGGER_SPEC):$(GO_SOURCES)$(SWAGGER_SPEC_INPUT)
272265
$(GO) run$(SWAGGER_PACKAGE) generate spec --exclude"$(SWAGGER_EXCLUDE)" --input"$(SWAGGER_SPEC_INPUT)" --output'./$(SWAGGER_SPEC)'
273266

274267
.PHONY: swagger-check
@@ -373,7 +366,7 @@ lint-go-gitea-vet: ## lint go files with gitea-vet
373366
.PHONY: lint-go-gopls
374367
lint-go-gopls:## lint go files with gopls
375368
@echo"Running gopls check..."
376-
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh$(GO_SOURCES_NO_BINDATA)
369+
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh$(GO_SOURCES)
377370

378371
.PHONY: lint-editorconfig
379372
lint-editorconfig:

‎build.go‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,10 @@
55

66
package main
77

8-
// Libraries that are included to vendor utilities used during build.
8+
// Libraries that are included to vendor utilities used duringMakefilebuild.
99
// These libraries will not be included in a normal compilation.
1010

1111
import (
12-
// for embed
13-
_"github.com/shurcooL/vfsgen"
14-
15-
// for cover merge
16-
_"golang.org/x/tools/cover"
17-
1812
// for vet
1913
_"code.gitea.io/gitea-vet"
20-
21-
// for swagger
22-
_"github.com/go-swagger/go-swagger/cmd/swagger"
2314
)

‎build/generate-bindata.go‎

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,22 @@
66
package main
77

88
import (
9-
"bytes"
10-
"crypto/sha1"
119
"fmt"
12-
"log"
13-
"net/http"
1410
"os"
15-
"path/filepath"
16-
"strconv"
1711

18-
"github.com/shurcooL/vfsgen"
12+
"code.gitea.io/gitea/modules/assetfs"
1913
)
2014

21-
funcneedsUpdate(dir,filenamestring) (bool, []byte) {
22-
needRegen:=false
23-
_,err:=os.Stat(filename)
24-
iferr!=nil {
25-
needRegen=true
26-
}
27-
28-
oldHash,err:=os.ReadFile(filename+".hash")
29-
iferr!=nil {
30-
oldHash= []byte{}
31-
}
32-
33-
hasher:=sha1.New()
34-
35-
err=filepath.WalkDir(dir,func(pathstring,d os.DirEntry,errerror)error {
36-
iferr!=nil {
37-
returnerr
38-
}
39-
info,err:=d.Info()
40-
iferr!=nil {
41-
returnerr
42-
}
43-
_,_=hasher.Write([]byte(d.Name()))
44-
_,_=hasher.Write([]byte(info.ModTime().String()))
45-
_,_=hasher.Write([]byte(strconv.FormatInt(info.Size(),16)))
46-
returnnil
47-
})
48-
iferr!=nil {
49-
returntrue,oldHash
50-
}
51-
52-
newHash:=hasher.Sum([]byte{})
53-
54-
ifbytes.Compare(oldHash,newHash)!=0 {
55-
returntrue,newHash
56-
}
57-
58-
returnneedRegen,newHash
59-
}
60-
6115
funcmain() {
62-
iflen(os.Args)<4 {
63-
log.Fatal("Insufficient number of arguments. Need: directory packageName filename")
64-
}
65-
66-
dir,packageName,filename:=os.Args[1],os.Args[2],os.Args[3]
67-
varuseGlobalModTimebool
68-
iflen(os.Args)==5 {
69-
useGlobalModTime,_=strconv.ParseBool(os.Args[4])
70-
}
71-
72-
update,newHash:=needsUpdate(dir,filename)
73-
74-
if!update {
75-
fmt.Printf("bindata for %s already up-to-date\n",packageName)
76-
return
16+
iflen(os.Args)!=3 {
17+
fmt.Println("usage: ./generate-bindata {local-directory} {bindata-filename}")
18+
os.Exit(1)
7719
}
7820

79-
fmt.Printf("generating bindata for %s\n",packageName)
80-
varfsTemplates http.FileSystem=http.Dir(dir)
81-
err:=vfsgen.Generate(fsTemplates, vfsgen.Options{
82-
PackageName:packageName,
83-
BuildTags:"bindata",
84-
VariableName:"Assets",
85-
Filename:filename,
86-
UseGlobalModTime:useGlobalModTime,
87-
})
88-
iferr!=nil {
89-
log.Fatalf("%v\n",err)
21+
dir,filename:=os.Args[1],os.Args[2]
22+
fmt.Printf("generating bindata for %s to %s\n",dir,filename)
23+
iferr:=assetfs.GenerateEmbedBindata(dir,filename);err!=nil {
24+
fmt.Printf("failed: %s\n",err.Error())
25+
os.Exit(1)
9026
}
91-
_=os.WriteFile(filename+".hash",newHash,0o666)
9227
}

‎cmd/embedded.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,23 @@ func initEmbeddedExtractor(c *cli.Command) error {
118118

119119
funcrunList(_ context.Context,c*cli.Command)error {
120120
iferr:=runListDo(c);err!=nil {
121-
fmt.Fprintf(os.Stderr,"%v\n",err)
121+
_,_=fmt.Fprintf(os.Stderr,"%v\n",err)
122122
returnerr
123123
}
124124
returnnil
125125
}
126126

127127
funcrunView(_ context.Context,c*cli.Command)error {
128128
iferr:=runViewDo(c);err!=nil {
129-
fmt.Fprintf(os.Stderr,"%v\n",err)
129+
_,_=fmt.Fprintf(os.Stderr,"%v\n",err)
130130
returnerr
131131
}
132132
returnnil
133133
}
134134

135135
funcrunExtract(_ context.Context,c*cli.Command)error {
136136
iferr:=runExtractDo(c);err!=nil {
137-
fmt.Fprintf(os.Stderr,"%v\n",err)
137+
_,_=fmt.Fprintf(os.Stderr,"%v\n",err)
138138
returnerr
139139
}
140140
returnnil
@@ -217,7 +217,7 @@ func runExtractDo(c *cli.Command) error {
217217
for_,a:=rangematchedAssetFiles {
218218
iferr:=extractAsset(destdir,a,overwrite,rename);err!=nil {
219219
// Non-fatal error
220-
fmt.Fprintf(os.Stderr,"%s: %v",a.path,err)
220+
_,_=fmt.Fprintf(os.Stderr,"%s: %v\n",a.path,err)
221221
}
222222
}
223223

‎go.mod‎

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ require (
6060
github.com/go-ldap/ldap/v3v3.4.11
6161
github.com/go-redsync/redsync/v4v4.13.0
6262
github.com/go-sql-driver/mysqlv1.9.2
63-
github.com/go-swagger/go-swaggerv0.31.0
6463
github.com/go-webauthn/webauthnv0.12.3
6564
github.com/gobwas/globv0.2.3
6665
github.com/gogs/chardetv0.0.0-20211120154057-b7413eaefb8f
@@ -105,7 +104,6 @@ require (
105104
github.com/santhosh-tekuri/jsonschema/v5v5.3.1
106105
github.com/sassoftware/go-rpmutilsv0.4.0
107106
github.com/sergi/go-diffv1.3.2-0.20230802210424-5b0b94c5c0d3
108-
github.com/shurcooL/vfsgenv0.0.0-20230704071429-0000e147ea92
109107
github.com/stretchr/testifyv1.10.0
110108
github.com/syndtr/goleveldbv1.0.0
111109
github.com/tstranex/u2fv1.0.0
@@ -126,7 +124,6 @@ require (
126124
golang.org/x/syncv0.15.0
127125
golang.org/x/sysv0.33.0
128126
golang.org/x/textv0.26.0
129-
golang.org/x/toolsv0.33.0
130127
google.golang.org/grpcv1.72.0
131128
google.golang.org/protobufv1.36.6
132129
gopkg.in/ini.v1v1.67.0
@@ -144,15 +141,11 @@ require (
144141
git.sr.ht/~mariusor/go-xsd-durationv0.0.0-20220703122237-02e73435a078// indirect
145142
github.com/Azure/azure-sdk-for-go/sdk/internalv1.11.1// indirect
146143
github.com/DataDog/zstdv1.5.7// indirect
147-
github.com/Masterminds/goutilsv1.1.1// indirect
148-
github.com/Masterminds/semver/v3v3.3.1// indirect
149-
github.com/Masterminds/sprig/v3v3.3.0// indirect
150144
github.com/Microsoft/go-winiov0.6.2// indirect
151145
github.com/RoaringBitmap/roaring/v2v2.4.5// indirect
152146
github.com/andybalholm/brotliv1.1.1// indirect
153147
github.com/andybalholm/cascadiav1.3.3// indirect
154148
github.com/anmitsu/go-shlexv0.0.0-20200514113438-38f4b401e2be// indirect
155-
github.com/asaskevich/govalidatorv0.0.0-20230301143203-a9d515a09cc2// indirect
156149
github.com/aws/aws-sdk-go-v2v1.36.3// indirect
157150
github.com/aws/aws-sdk-go-v2/internal/configsourcesv1.3.34// indirect
158151
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2v2.6.34// indirect
@@ -195,7 +188,6 @@ require (
195188
github.com/dlclark/regexp2v1.11.5// indirect
196189
github.com/emersion/go-saslv0.0.0-20241020182733-b788ff22d5a6// indirect
197190
github.com/fatih/colorv1.18.0// indirect
198-
github.com/felixge/httpsnoopv1.0.4// indirect
199191
github.com/fxamacker/cbor/v2v2.8.0// indirect
200192
github.com/git-lfs/pktlinev0.0.0-20230103162542-ca444d533ef1// indirect
201193
github.com/go-ap/errorsv0.0.0-20250409143711-5686c11ae650// indirect
@@ -204,18 +196,6 @@ require (
204196
github.com/go-fed/httpsigv1.1.1-0.20201223112313-55836744818e// indirect
205197
github.com/go-git/gcfgv1.5.1-0.20230307220236-3a3c6141e376// indirect
206198
github.com/go-ini/iniv1.67.0// indirect
207-
github.com/go-openapi/analysisv0.23.0// indirect
208-
github.com/go-openapi/errorsv0.22.1// indirect
209-
github.com/go-openapi/inflectv0.21.2// indirect
210-
github.com/go-openapi/jsonpointerv0.21.1// indirect
211-
github.com/go-openapi/jsonreferencev0.21.0// indirect
212-
github.com/go-openapi/loadsv0.22.0// indirect
213-
github.com/go-openapi/runtimev0.28.0// indirect
214-
github.com/go-openapi/specv0.21.0// indirect
215-
github.com/go-openapi/strfmtv0.23.0// indirect
216-
github.com/go-openapi/swagv0.23.1// indirect
217-
github.com/go-openapi/validatev0.24.0// indirect
218-
github.com/go-viper/mapstructure/v2v2.2.1// indirect
219199
github.com/go-webauthn/xv0.1.20// indirect
220200
github.com/goccy/go-jsonv0.10.5// indirect
221201
github.com/golang-jwt/jwt/v4v4.5.2// indirect
@@ -229,20 +209,16 @@ require (
229209
github.com/google/go-querystringv1.1.0// indirect
230210
github.com/google/go-tpmv0.9.3// indirect
231211
github.com/gorilla/cssv1.0.1// indirect
232-
github.com/gorilla/handlersv1.5.2// indirect
233212
github.com/gorilla/muxv1.8.1// indirect
234213
github.com/gorilla/securecookiev1.1.2// indirect
235214
github.com/hashicorp/errwrapv1.1.0// indirect
236215
github.com/hashicorp/go-cleanhttpv0.5.2// indirect
237216
github.com/hashicorp/go-multierrorv1.1.1// indirect
238217
github.com/hashicorp/go-retryablehttpv0.7.7// indirect
239218
github.com/jbenet/go-contextv0.0.0-20150711004518-d14ea06fba99// indirect
240-
github.com/jessevdk/go-flagsv1.6.1// indirect
241219
github.com/josharian/internv1.0.0// indirect
242220
github.com/kevinburke/ssh_configv1.2.0// indirect
243221
github.com/klauspost/pgzipv1.2.6// indirect
244-
github.com/kr/prettyv0.3.1// indirect
245-
github.com/kr/textv0.2.0// indirect
246222
github.com/libdns/libdnsv1.0.0-beta.1// indirect
247223
github.com/mailru/easyjsonv0.9.0// indirect
248224
github.com/markbates/goingv1.0.3// indirect
@@ -253,19 +229,15 @@ require (
253229
github.com/miekg/dnsv1.1.65// indirect
254230
github.com/minio/crc64nvmev1.0.1// indirect
255231
github.com/minio/md5-simdv1.1.2// indirect
256-
github.com/mitchellh/copystructurev1.2.0// indirect
257232
github.com/mitchellh/mapstructurev1.5.0// indirect
258-
github.com/mitchellh/reflectwalkv1.0.2// indirect
259233
github.com/modern-go/concurrentv0.0.0-20180306012644-bacd9c7ef1dd// indirect
260234
github.com/modern-go/reflect2v1.0.2// indirect
261235
github.com/mrjones/oauthv0.0.0-20190623134757-126b35219450// indirect
262236
github.com/mschoch/smatv0.2.0// indirect
263237
github.com/munnerz/goautonegv0.0.0-20191010083416-a7dc8b61c822// indirect
264238
github.com/nwaples/rardecodev1.1.3// indirect
265-
github.com/oklog/ulidv1.3.1// indirect
266239
github.com/olekukonko/tablewriterv0.0.5// indirect
267240
github.com/onsi/ginkgov1.16.5// indirect
268-
github.com/pelletier/go-toml/v2v2.2.4// indirect
269241
github.com/pierrec/lz4/v4v4.1.22// indirect
270242
github.com/pjbgf/sha1cdv0.3.2// indirect
271243
github.com/pmezard/go-difflibv1.0.1-0.20181226105442-5d4384ee4fb2// indirect
@@ -274,22 +246,11 @@ require (
274246
github.com/prometheus/procfsv0.16.1// indirect
275247
github.com/rhysd/actionlintv1.7.7// indirect
276248
github.com/rivo/unisegv0.4.7// indirect
277-
github.com/rogpeppe/go-internalv1.14.1// indirect
278249
github.com/rs/xidv1.6.0// indirect
279250
github.com/russross/blackfriday/v2v2.1.0// indirect
280-
github.com/sagikazarmark/locaferov0.9.0// indirect
281-
github.com/shopspring/decimalv1.4.0// indirect
282-
github.com/shurcooL/httpfsv0.0.0-20230704072500-f1e31cf0ba5c// indirect
283251
github.com/sirupsen/logrusv1.9.3// indirect
284252
github.com/skeema/knownhostsv1.3.1// indirect
285-
github.com/sourcegraph/concv0.3.0// indirect
286-
github.com/spf13/aferov1.14.0// indirect
287-
github.com/spf13/castv1.7.1// indirect
288-
github.com/spf13/pflagv1.0.6// indirect
289-
github.com/spf13/viperv1.20.1// indirect
290253
github.com/ssor/bomv0.0.0-20170718123548-6386211fdfcf// indirect
291-
github.com/subosito/gotenvv1.6.0// indirect
292-
github.com/toqueteos/webbrowserv1.2.0// indirect
293254
github.com/unknwon/comv1.0.1// indirect
294255
github.com/valyala/fastjsonv1.6.4// indirect
295256
github.com/x448/float16v0.8.4// indirect
@@ -300,23 +261,21 @@ require (
300261
github.com/zeebo/assertv1.3.0// indirect
301262
github.com/zeebo/blake3v0.2.4// indirect
302263
go.etcd.io/bboltv1.4.0// indirect
303-
go.mongodb.org/mongo-driverv1.17.3// indirect
304264
go.uber.org/atomicv1.11.0// indirect
305265
go.uber.org/multierrv1.11.0// indirect
306266
go.uber.org/zapv1.27.0// indirect
307267
go.uber.org/zap/expv0.3.0// indirect
308268
golang.org/x/expv0.0.0-20250305212735-054e65f0b394// indirect
309269
golang.org/x/modv0.25.0// indirect
310270
golang.org/x/timev0.11.0// indirect
271+
golang.org/x/toolsv0.33.0// indirect
311272
google.golang.org/genproto/googleapis/rpcv0.0.0-20250422160041-2d3770c4ea7f// indirect
312273
gopkg.in/warnings.v0v0.1.2// indirect
313274
gopkg.in/yaml.v2v2.4.0// indirect
314275
)
315276

316277
replacegithub.com/hashicorp/go-version =>github.com/6543/go-versionv1.3.1
317278

318-
replacegithub.com/shurcooL/vfsgen =>github.com/lunny/vfsgenv0.0.0-20220105142115-2c99e1ffdfa0
319-
320279
replacegithub.com/nektos/act =>gitea.com/gitea/actv0.261.6
321280

322281
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp