53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package managementasset
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
IndexFile = "index.html"
|
|
ManagementFile = "management.html"
|
|
)
|
|
|
|
// Source describes the filesystem and entry file used for the management UI.
|
|
type Source struct {
|
|
FileSystem http.FileSystem
|
|
Entry string
|
|
}
|
|
|
|
// Current returns the configured management UI source.
|
|
func Current() (*Source, error) {
|
|
if override := strings.TrimSpace(os.Getenv("MANAGEMENT_STATIC_PATH")); override != "" {
|
|
cleaned := filepath.Clean(override)
|
|
info, err := os.Stat(cleaned)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !info.IsDir() {
|
|
return &Source{
|
|
FileSystem: http.Dir(filepath.Dir(cleaned)),
|
|
Entry: filepath.Base(cleaned),
|
|
}, nil
|
|
}
|
|
|
|
entry := IndexFile
|
|
if _, err = os.Stat(filepath.Join(cleaned, entry)); err != nil {
|
|
if !os.IsNotExist(err) {
|
|
return nil, err
|
|
}
|
|
entry = ManagementFile
|
|
}
|
|
return &Source{FileSystem: http.Dir(cleaned), Entry: entry}, nil
|
|
}
|
|
|
|
files := embeddedFiles()
|
|
if files == nil {
|
|
return nil, fs.ErrNotExist
|
|
}
|
|
return &Source{FileSystem: http.FS(files), Entry: IndexFile}, nil
|
|
}
|