github.com/replicatedhq/ship@v0.55.0/pkg/lifecycle/daemon/ui.go (about) 1 // Thanks Gin! 2 // https://github.com/gin-gonic/contrib/blob/master/static/example/bindata/example.go 3 package daemon 4 5 import ( 6 "net/http" 7 "strings" 8 9 assetfs "github.com/elazarl/go-bindata-assetfs" 10 "github.com/go-kit/kit/log" 11 "github.com/go-kit/kit/log/level" 12 ) 13 14 type binaryFileSystem struct { 15 fs http.FileSystem 16 Logger log.Logger 17 } 18 19 func (b *binaryFileSystem) Open(name string) (http.File, error) { 20 level.Debug(b.Logger).Log("event", "file.open", "name", name) 21 return b.fs.Open(name) 22 } 23 24 func (b *binaryFileSystem) Exists(prefix string, filepath string) bool { 25 debug := level.Debug(log.With(b.Logger, "prefix", prefix, "filepath", filepath)) 26 debug.Log("event", "file.exists") 27 if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) { 28 if _, err := b.fs.Open(p); err != nil { 29 debug.Log("event", "file.open.err", "err", err) 30 return false 31 } 32 debug.Log("event", "file.open.success") 33 return true 34 } 35 debug.Log("event", "file.prefix.miss") 36 return false 37 } 38 39 type WebUIBuilder func(root string) *binaryFileSystem 40 41 func WebUIFactoryFactory( 42 logger log.Logger, 43 ) WebUIBuilder { 44 45 return func(root string) *binaryFileSystem { 46 fs := &assetfs.AssetFS{ 47 Asset: Asset, 48 AssetDir: AssetDir, 49 AssetInfo: AssetInfo, 50 Prefix: root, 51 } 52 return &binaryFileSystem{ 53 fs: fs, 54 Logger: logger, 55 } 56 } 57 }