Skip to content

Commit 6a97f49

Browse files
committed
Replace go.rice module with std embed
1 parent 3d8bc22 commit 6a97f49

14 files changed

Lines changed: 61 additions & 155 deletions

File tree

fileserver/fileserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func localRedirect(w http.ResponseWriter, r *http.Request, newPath string) {
229229
// To use the operating system's file system implementation,
230230
// use http.Dir:
231231
//
232-
// http.Handle("/", &fileserver.FileServer{Root: http.Dir("/tmp")})
232+
// http.Handle("/", &fileserver.FileServer{Root: http.Dir("/tmp")})
233233
type FileServer struct {
234234
Version string
235235
Root http.FileSystem

fileserver/fileserver_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"testing"
2424
"time"
2525

26-
rice "github.com/GeertJohan/go.rice"
26+
"github.com/cortesi/devd/fstmpl"
2727
"github.com/cortesi/devd/inject"
28-
"github.com/cortesi/devd/ricetemp"
2928
"github.com/cortesi/devd/routespec"
29+
"github.com/cortesi/devd/templates"
3030
"github.com/cortesi/termlog"
3131
)
3232

@@ -40,7 +40,7 @@ func ServeFile(w http.ResponseWriter, r *http.Request, name string) {
4040
"version",
4141
http.Dir(dir),
4242
inject.CopyInject{},
43-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
43+
fstmpl.MustMakeTemplates(templates.FS),
4444
[]routespec.RouteSpec{},
4545
"",
4646
}
@@ -168,7 +168,7 @@ func TestFSRedirect(t *testing.T) {
168168
"version",
169169
http.Dir("."),
170170
inject.CopyInject{},
171-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
171+
fstmpl.MustMakeTemplates(templates.FS),
172172
[]routespec.RouteSpec{},
173173
"",
174174
},
@@ -208,7 +208,7 @@ func _TestFileServerCleans(t *testing.T) {
208208
},
209209
},
210210
inject.CopyInject{},
211-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
211+
fstmpl.MustMakeTemplates(templates.FS),
212212
[]routespec.RouteSpec{},
213213
"",
214214
}
@@ -250,7 +250,7 @@ func TestFileServerImplicitLeadingSlash(t *testing.T) {
250250
"version",
251251
http.Dir(tempDir),
252252
inject.CopyInject{},
253-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
253+
fstmpl.MustMakeTemplates(templates.FS),
254254
[]routespec.RouteSpec{},
255255
"",
256256
}
@@ -415,7 +415,7 @@ func TestServeIndexHtml(t *testing.T) {
415415
"version",
416416
http.Dir("."),
417417
inject.CopyInject{},
418-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
418+
fstmpl.MustMakeTemplates(templates.FS),
419419
[]routespec.RouteSpec{},
420420
"",
421421
}
@@ -444,7 +444,7 @@ func TestFileServerZeroByte(t *testing.T) {
444444
"version",
445445
http.Dir("."),
446446
inject.CopyInject{},
447-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
447+
fstmpl.MustMakeTemplates(templates.FS),
448448
[]routespec.RouteSpec{},
449449
"",
450450
}
@@ -539,7 +539,7 @@ func TestNotFoundOverride(t *testing.T) {
539539
"version",
540540
fsys,
541541
inject.CopyInject{},
542-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
542+
fstmpl.MustMakeTemplates(templates.FS),
543543
[]routespec.RouteSpec{
544544
{Host: "", Path: "/", Value: "foo.html"},
545545
},
@@ -611,7 +611,7 @@ func TestDirectoryIfNotModified(t *testing.T) {
611611
"version",
612612
fsys,
613613
inject.CopyInject{},
614-
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
614+
fstmpl.MustMakeTemplates(templates.FS),
615615
[]routespec.RouteSpec{},
616616
"",
617617
}
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
// Package ricetemp makes templates from a ricebox.
2-
package ricetemp
1+
// Package embedtmpl makes templates from a fs.FS
2+
package fstmpl
33

44
import (
55
"html/template"
6+
"io"
7+
"io/fs"
68
"os"
79
"strings"
810

9-
"github.com/GeertJohan/go.rice"
1011
"github.com/dustin/go-humanize"
1112
)
1213

@@ -25,16 +26,16 @@ func fileType(f os.FileInfo) string {
2526
}
2627

2728
// MustMakeTemplates makes templates, and panic on error
28-
func MustMakeTemplates(rb *rice.Box) *template.Template {
29-
templates, err := MakeTemplates(rb)
29+
func MustMakeTemplates(fs fs.ReadDirFS) *template.Template {
30+
templates, err := MakeTemplates(fs)
3031
if err != nil {
3132
panic(err)
3233
}
3334
return templates
3435
}
3536

3637
// MakeTemplates takes a rice.Box and returns a html.Template
37-
func MakeTemplates(rb *rice.Box) (*template.Template, error) {
38+
func MakeTemplates(fs fs.ReadDirFS) (*template.Template, error) {
3839
tmpl := template.New("")
3940

4041
funcMap := template.FuncMap{
@@ -44,14 +45,20 @@ func MakeTemplates(rb *rice.Box) (*template.Template, error) {
4445
}
4546
tmpl.Funcs(funcMap)
4647

47-
err := rb.Walk("", func(path string, info os.FileInfo, err error) error {
48-
if !info.IsDir() {
49-
_, err := tmpl.New(path).Parse(rb.MustString(path))
50-
if err != nil {
51-
return err
52-
}
48+
ds, err := fs.ReadDir(".")
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
for _, d := range ds {
54+
f, _ := fs.Open(d.Name())
55+
fbs, _ := io.ReadAll(f)
56+
57+
_, err := tmpl.New(d.Name()).Parse(string(fbs))
58+
if err != nil {
59+
return nil, err
5360
}
54-
return nil
55-
})
61+
}
62+
5663
return tmpl, err
5764
}

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/cortesi/devd
33
go 1.25.0
44

55
require (
6-
github.com/GeertJohan/go.rice v1.0.3
76
github.com/cortesi/moddwatch v0.1.0
87
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0
98
github.com/dustin/go-humanize v1.0.1
@@ -21,7 +20,7 @@ require (
2120
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
2221
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
2322
github.com/bmatcuk/doublestar v1.3.4 // indirect
24-
github.com/daaku/go.zipexe v1.0.2 // indirect
23+
github.com/davecgh/go-spew v1.1.1 // indirect
2524
github.com/google/go-cmp v0.6.0 // indirect
2625
github.com/kr/text v0.2.0 // indirect
2726
github.com/mattn/go-colorable v0.1.14 // indirect

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
2-
github.com/GeertJohan/go.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
3-
github.com/GeertJohan/go.rice v1.0.3/go.mod h1:XVdrU4pW00M4ikZed5q56tPf1v2KwnIKeIdc9CBYNt4=
4-
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
51
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
62
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
73
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
@@ -13,8 +9,6 @@ github.com/cortesi/moddwatch v0.1.0/go.mod h1:PFkhcmmwsRMQ76IMjKbaIIMcGQt7BSMtFO
139
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0 h1:i6kD96U0+1ht4pxADqe3Vz+P44SN8TeBS4A5bPidu90=
1410
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0/go.mod h1:GjgJh2CGR2AEiiH4po295B0ZEKRrt+0P1mlLrGwos+w=
1511
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
16-
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
17-
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
1812
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1913
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2014
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -29,7 +23,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2923
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3024
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
3125
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
32-
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
3326
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
3427
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
3528
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -44,7 +37,6 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
4437
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
4538
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
4639
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
47-
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
4840
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4941
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5042
github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY=
@@ -55,8 +47,6 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
5547
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
5648
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
5749
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
58-
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
59-
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
6050
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
6151
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
6252
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

livereload/livereload.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
package livereload
44

55
import (
6+
_ "embed"
67
"net/http"
78
"regexp"
89
"strings"
910
"sync"
1011

11-
"github.com/GeertJohan/go.rice"
1212
"github.com/cortesi/devd/inject"
1313
"github.com/cortesi/termlog"
1414
"github.com/gorilla/websocket"
1515
)
1616

17+
//go:embed client.js
18+
var clientJS []byte
19+
20+
//go:embed LICENSE
21+
var license []byte
22+
1723
// Reloader triggers a reload
1824
type Reloader interface {
1925
Reload(paths []string)
@@ -130,8 +136,7 @@ func (s *Server) Watch(ch chan []string) {
130136
// ServeScript is a handler function that serves the livereload JavaScript file
131137
func (s *Server) ServeScript(rw http.ResponseWriter, req *http.Request) {
132138
rw.Header().Set("Content-Type", "application/javascript")
133-
clientBox := rice.MustFindBox("static")
134-
_, err := rw.Write(clientBox.MustBytes("client.js"))
139+
_, err := rw.Write(clientJS)
135140
if err != nil {
136141
s.logger.Warn("Error serving livereload script: %s", err)
137142
}

0 commit comments

Comments
 (0)