github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/filesystem/fsutil/http-stack.go (about)

     1  package fsutil
     2  
     3  import (
     4  	"net/http"
     5  )
     6  
     7  // HTTPStackedFileSystem implements http.FileSystem by falling back through multiple layers
     8  // to find where a file exists and using the first match.  FileSystems are checked in the
     9  // order provided, i.e. index 0 takes precedence over all others, etc.
    10  type HTTPStackedFileSystem struct {
    11  	Stack []http.FileSystem
    12  }
    13  
    14  func NewHTTPStackedFileSystem(subfss ...http.FileSystem) *HTTPStackedFileSystem {
    15  	return &HTTPStackedFileSystem{
    16  		Stack: subfss,
    17  	}
    18  }
    19  
    20  func (fs *HTTPStackedFileSystem) Open(name string) (ret http.File, err error) {
    21  	for _, subfs := range fs.Stack {
    22  		ret, err = subfs.Open(name)
    23  		if err == nil {
    24  			break
    25  		}
    26  	}
    27  	return
    28  }