vise/go/resource/fs.go

46 lines
833 B
Go
Raw Normal View History

2023-03-31 11:52:04 +02:00
package resource
import (
2023-04-01 11:58:02 +02:00
"fmt"
"io/ioutil"
"path"
"path/filepath"
2023-04-01 11:58:02 +02:00
"strings"
2023-03-31 11:52:04 +02:00
)
type FsResource struct {
MenuResource
2023-04-01 15:47:03 +02:00
Path string
2023-03-31 11:52:04 +02:00
}
func NewFsResource(path string) (FsResource) {
absPath, err := filepath.Abs(path)
if err != nil {
panic(err)
}
2023-03-31 11:52:04 +02:00
return FsResource{
Path: absPath,
2023-03-31 11:52:04 +02:00
}
}
func(fs FsResource) GetTemplate(sym string, sizer *Sizer) (string, error) {
2023-04-01 15:47:03 +02:00
fp := path.Join(fs.Path, sym)
2023-04-01 11:58:02 +02:00
r, err := ioutil.ReadFile(fp)
s := string(r)
return strings.TrimSpace(s), err
2023-03-31 11:52:04 +02:00
}
2023-04-01 11:58:02 +02:00
func(fs FsResource) GetCode(sym string) ([]byte, error) {
fb := sym + ".bin"
fp := path.Join(fs.Path, fb)
return ioutil.ReadFile(fp)
2023-04-01 11:58:02 +02:00
}
func(fs FsResource) FuncFor(sym string) (EntryFunc, error) {
return nil, fmt.Errorf("not implemented")
}
func(rs FsResource) String() string {
return fmt.Sprintf("fs resource at path: %s", rs.Path)
}