feat(comicverse): support for local assets files
This commit is contained in:
@@ -109,8 +109,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *dev {
|
if *dev {
|
||||||
d := os.DirFS("./static")
|
d := os.DirFS("./assets")
|
||||||
opts = append(opts, comicverse.WithStaticFiles(d))
|
opts = append(opts, comicverse.WithAssets(d))
|
||||||
|
|
||||||
opts = append(opts, comicverse.WithDevelopmentMode())
|
opts = append(opts, comicverse.WithDevelopmentMode())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"forge.capytal.company/capytalcode/project-comicverse/assets"
|
"forge.capytal.company/capytalcode/project-comicverse/assets"
|
||||||
"forge.capytal.company/capytalcode/project-comicverse/database"
|
"forge.capytal.company/capytalcode/project-comicverse/database"
|
||||||
|
"forge.capytal.company/capytalcode/project-comicverse/internals/joinedfs"
|
||||||
"forge.capytal.company/capytalcode/project-comicverse/router"
|
"forge.capytal.company/capytalcode/project-comicverse/router"
|
||||||
"forge.capytal.company/capytalcode/project-comicverse/service"
|
"forge.capytal.company/capytalcode/project-comicverse/service"
|
||||||
"forge.capytal.company/capytalcode/project-comicverse/templates"
|
"forge.capytal.company/capytalcode/project-comicverse/templates"
|
||||||
@@ -77,8 +78,8 @@ func WithContext(ctx context.Context) Option {
|
|||||||
return func(app *app) { app.ctx = ctx }
|
return func(app *app) { app.ctx = ctx }
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithStaticFiles(f fs.FS) Option {
|
func WithAssets(f fs.FS) Option {
|
||||||
return func(app *app) { app.staticFiles = f }
|
return func(app *app) { app.assets = joinedfs.Join(f, app.assets) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithAssertions(a tinyssert.Assertions) Option {
|
func WithAssertions(a tinyssert.Assertions) Option {
|
||||||
|
|||||||
25
internals/joinedfs/joinedfs.go
Normal file
25
internals/joinedfs/joinedfs.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package joinedfs
|
||||||
|
|
||||||
|
import "io/fs"
|
||||||
|
|
||||||
|
func Join(fsys ...fs.FS) fs.FS {
|
||||||
|
return &joinedFS{fsys}
|
||||||
|
}
|
||||||
|
|
||||||
|
type joinedFS struct {
|
||||||
|
fsys []fs.FS
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fs.FS = (*joinedFS)(nil)
|
||||||
|
|
||||||
|
func (j *joinedFS) Open(name string) (fs.File, error) {
|
||||||
|
var err error
|
||||||
|
var f fs.File
|
||||||
|
for _, fsys := range j.fsys {
|
||||||
|
f, err = fsys.Open(name)
|
||||||
|
if err == nil {
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user