github.com/icexin/eggos@v0.4.2-0.20220216025428-78b167e4f349/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  }