mirror of
https://github.com/cnrancher/kube-explorer.git
synced 2025-07-12 14:08:33 +00:00
- Support embed api-ui resources - The ui-path arg will be applied if provided. Also applied to api-ui resource files
42 lines
765 B
Go
42 lines
765 B
Go
package content
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
func NewFilepath(getPath func() string) Handler {
|
|
return newFS(&filepathFS{
|
|
getPath: getPath,
|
|
})
|
|
}
|
|
|
|
var _ fsContent = &filepathFS{}
|
|
|
|
type filepathFS struct {
|
|
getPath func() string
|
|
}
|
|
|
|
func (f *filepathFS) ToFileServer(basePaths ...string) http.Handler {
|
|
root := f.getPath()
|
|
if root == "" {
|
|
return http.NotFoundHandler()
|
|
}
|
|
path := filepath.Join(append([]string{string(root)}, basePaths...)...)
|
|
return http.FileServer(http.Dir(path))
|
|
}
|
|
|
|
func (f *filepathFS) Open(name string) (fs.File, error) {
|
|
root := f.getPath()
|
|
if root == "" {
|
|
return nil, errors.New("filepath fs is not ready")
|
|
}
|
|
return http.Dir(root).Open(name)
|
|
}
|
|
|
|
func (f *filepathFS) Refresh() error {
|
|
return nil
|
|
}
|