Skip to content

Commit e47bdd1

Browse files
committed
migrate from vfs to go:embed
1 parent ff821dc commit e47bdd1

10 files changed

+19
-76
lines changed

.goreleaser.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
before:
22
hooks:
33
- go mod tidy
4-
- go generate .
54
builds:
65
- env:
76
- CGO_ENABLED=0
87
main: .
9-
flags:
10-
- -tags=vfs
118
ldflags: -s -w -X main.VERSION={{.Version}} -X main.BUILDTIME={{.Date}} -X main.GITCOMMIT={{.Commit}}
129
goos:
1310
- linux

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ Depdencies are managed by [govendor](https://github.com/kardianos/govendor)
314314
2. Build single binary release
315315

316316
```sh
317-
$ go generate .
318-
$ go build -tags vfs
317+
$ go build
319318
```
320319

321320
Theme are defined in [assets/themes](assets/themes) directory. Now only two themes are available, "black" and "green".
@@ -335,7 +334,7 @@ Theme are defined in [assets/themes](assets/themes) directory. Now only two them
335334

336335
**Go Libraries**
337336

338-
* [vfsgen](https://github.com/shurcooL/vfsgen)
337+
* [vfsgen](https://github.com/shurcooL/vfsgen) Not using now
339338
* [go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs) Not using now
340339
* <http://www.gorillatoolkit.org/pkg/handlers>
341340

assets.go

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"embed"
5+
"net/http"
6+
)
7+
8+
//go:embed assets
9+
var assetsFS embed.FS
10+
11+
// Assets contains project assets.
12+
var Assets = http.FS(assetsFS)

assets_dev.go

-9
This file was deleted.

assets_generate.go

-23
This file was deleted.

build.sh

-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ fi
2323
build() {
2424
echo "$1 $2 ..."
2525
GOOS=$1 GOARCH=$2 go build \
26-
-tags vfs \
2726
-ldflags "$LDFLAGS" \
2827
-o dist/gohttpserver-${3:-""}
2928
}
3029

31-
go generate .
32-
3330
build linux arm linux-arm
3431
build darwin amd64 mac-amd64
3532
build linux amd64 linux-amd64

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ require (
1717
github.com/gorilla/sessions v1.1.3
1818
github.com/pkg/errors v0.8.0 // indirect
1919
github.com/shogo82148/androidbinary v0.0.0-20180627093851-01c4bfa8b3b5
20-
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 // indirect
21-
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca
2220
github.com/smartystreets/goconvey v1.6.4 // indirect
2321
github.com/stretchr/testify v1.3.0
22+
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
2423
golang.org/x/text v0.3.3
25-
golang.org/x/tools v0.1.0 // indirect
2624
howett.net/plist v0.0.0-20201203080718-1454fab16a06 // indirect
2725
)

go.sum

-17
Original file line numberDiff line numberDiff line change
@@ -44,44 +44,27 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
4444
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4545
github.com/shogo82148/androidbinary v0.0.0-20180627093851-01c4bfa8b3b5 h1:bXRaUWl3Afe3F9YR5NU1U3UB5zjCHlu4im5p3J/LUYk=
4646
github.com/shogo82148/androidbinary v0.0.0-20180627093851-01c4bfa8b3b5/go.mod h1:05AjXWPWLdTIl9+REKhSmTeoJ6Wz5e9ir0Q0NRxCIKo=
47-
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 h1:SWV2fHctRpRrp49VXJ6UZja7gU9QLHwRpIPBN89SKEo=
48-
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
49-
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca h1:3fECS8atRjByijiI8yYiuwLwQ2ZxXobW7ua/8GRB3pI=
50-
github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
5147
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
5248
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
5349
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
5450
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
5551
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5652
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
5753
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
58-
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
5954
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
60-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
6155
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
62-
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
6356
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
6457
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
65-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
6658
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
6759
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
68-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
69-
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7060
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7161
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7262
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
73-
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7463
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7564
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
7665
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
7766
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
7867
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
79-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
80-
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
81-
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
82-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
83-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
84-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
8568
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8669
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
8770
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

httpstaticserver.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
142142
if r.Method == "HEAD" {
143143
return
144144
}
145-
renderHTML(w, "index.html", s)
145+
renderHTML(w, "assets/index.html", s)
146146
} else {
147147
if filepath.Base(path) == YAMLCONF {
148148
auth := s.readAccessConf(realPath)
@@ -423,7 +423,7 @@ func (s *HTTPStaticServer) hIpaLink(w http.ResponseWriter, r *http.Request) {
423423

424424
w.Header().Set("Content-Type", "text/html")
425425
log.Println("PlistURL:", plistUrl)
426-
renderHTML(w, "ipa-install.html", map[string]string{
426+
renderHTML(w, "assets/ipa-install.html", map[string]string{
427427
"Name": filepath.Base(path),
428428
"PlistLink": plistUrl,
429429
})
@@ -784,7 +784,7 @@ var (
784784
_tmpls = make(map[string]*template.Template)
785785
)
786786

787-
func executeTemplate(w http.ResponseWriter, name string, v interface{}) {
787+
func renderHTML(w http.ResponseWriter, name string, v interface{}) {
788788
if t, ok := _tmpls[name]; ok {
789789
t.Execute(w, v)
790790
return
@@ -794,16 +794,6 @@ func executeTemplate(w http.ResponseWriter, name string, v interface{}) {
794794
t.Execute(w, v)
795795
}
796796

797-
func renderHTML(w http.ResponseWriter, name string, v interface{}) {
798-
if _, ok := Assets.(http.Dir); ok {
799-
log.Println("Hot load", name)
800-
t := template.Must(template.New(name).Funcs(funcMap).Delims("[[", "]]").Parse(assetsContent(name)))
801-
t.Execute(w, v)
802-
} else {
803-
executeTemplate(w, name, v)
804-
}
805-
}
806-
807797
func checkFilename(name string) error {
808798
if strings.ContainsAny(name, "\\/:*<>|") {
809799
return errors.New("Name should not contains \\/:*<>|")

main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/goji/httpauth"
2323
"github.com/gorilla/handlers"
2424
"github.com/gorilla/mux"
25-
_ "github.com/shurcooL/vfsgen"
2625
)
2726

2827
type Configure struct {
@@ -224,7 +223,7 @@ func main() {
224223
})
225224
}
226225

227-
router.PathPrefix("/-/assets/").Handler(http.StripPrefix(gcfg.Prefix+"/-/assets/", http.FileServer(Assets)))
226+
router.PathPrefix("/-/assets/").Handler(http.StripPrefix(gcfg.Prefix+"/-/", http.FileServer(Assets)))
228227
router.HandleFunc("/-/sysinfo", func(w http.ResponseWriter, r *http.Request) {
229228
data, _ := json.Marshal(map[string]interface{}{
230229
"version": VERSION,

0 commit comments

Comments
 (0)