2023-03-31 11:52:04 +02:00
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
2023-04-01 11:58:02 +02:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
2023-04-02 11:11:09 +02:00
|
|
|
"path/filepath"
|
2023-04-01 11:58:02 +02:00
|
|
|
"strings"
|
2023-03-31 11:52:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type FsResource struct {
|
2023-04-01 15:47:03 +02:00
|
|
|
Path string
|
2023-03-31 11:52:04 +02:00
|
|
|
}
|
|
|
|
|
2023-04-02 11:11:09 +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{
|
2023-04-02 11:11:09 +02:00
|
|
|
Path: absPath,
|
2023-03-31 11:52:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-01 11:58:02 +02:00
|
|
|
func(fs FsResource) GetTemplate(sym string) (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) RenderTemplate(sym string, values map[string]string) (string, error) {
|
2023-04-02 11:11:09 +02:00
|
|
|
return DefaultRenderTemplate(&fs, sym, values)
|
2023-03-31 11:52:04 +02:00
|
|
|
}
|
2023-04-01 11:58:02 +02:00
|
|
|
|
|
|
|
func(fs FsResource) GetCode(sym string) ([]byte, error) {
|
2023-04-02 11:11:09 +02:00
|
|
|
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")
|
|
|
|
}
|
2023-04-02 11:11:09 +02:00
|
|
|
|
|
|
|
func(rs FsResource) String() string {
|
|
|
|
return fmt.Sprintf("fs resource at path: %s", rs.Path)
|
|
|
|
}
|