github.com/jspc/eggos@v0.5.1-0.20221028160421-556c75c878a5/assets/pkg.go (about)

     1  package assets
     2  
     3  import (
     4  	"net/http"
     5  	"sync"
     6  
     7  	"github.com/rakyll/statik/fs"
     8  )
     9  
    10  //go:generate statik -m -src=./files -dest .. -p assets
    11  
    12  var (
    13  	rootfs http.FileSystem
    14  	once   sync.Once
    15  )
    16  
    17  func FS() http.FileSystem {
    18  	var err error
    19  	once.Do(func() {
    20  		rootfs, err = fs.New()
    21  	})
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	return rootfs
    26  }
    27  
    28  func Open(fname string) (http.File, error) {
    29  	fs := FS()
    30  	return fs.Open(fname)
    31  }