32 lines
641 B
Go
32 lines
641 B
Go
package modweb
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type JoinedFilesystem struct {
|
|
DefaultSystem http.FileSystem
|
|
Systems map[string]http.FileSystem
|
|
}
|
|
|
|
func (s *JoinedFilesystem) Open(filename string) (http.File, error) {
|
|
for prefix, fs := range s.Systems {
|
|
if strings.HasPrefix(filename, prefix) {
|
|
file, err := fs.Open(filename)
|
|
if err == nil {
|
|
return file, nil
|
|
}
|
|
}
|
|
}
|
|
return s.DefaultSystem.Open(filename)
|
|
}
|
|
|
|
func (s *JoinedFilesystem) Register(prefix string, system http.FileSystem) {
|
|
s.Systems[prefix] = system
|
|
}
|
|
|
|
func JoinedFS(def http.FileSystem) *JoinedFilesystem {
|
|
return &JoinedFilesystem{DefaultSystem: def}
|
|
}
|