1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package assets
- import (
- "io/ioutil"
- "net/http"
- "os"
- "path"
- "github.com/rakyll/statik/fs"
- )
- var (
-
- FileSystem http.FileSystem
-
- prefixPath string
- )
- func Load(path string) (err error) {
- prefixPath = path
- if prefixPath != "" {
- FileSystem = http.Dir(prefixPath)
- return nil
- } else {
- FileSystem, err = fs.New()
- }
- return err
- }
- func ReadFile(file string) (content string, err error) {
- if prefixPath == "" {
- file, err := FileSystem.Open(path.Join("/", file))
- if err != nil {
- return content, err
- }
- defer file.Close()
- buf, err := ioutil.ReadAll(file)
- if err != nil {
- return content, err
- }
- content = string(buf)
- } else {
- file, err := os.Open(path.Join(prefixPath, file))
- if err != nil {
- return content, err
- }
- defer file.Close()
- buf, err := ioutil.ReadAll(file)
- if err != nil {
- return content, err
- }
- content = string(buf)
- }
- return content, err
- }
|