lang: Add an embedded package for embedded imports

This adds a new "embedded" package which can be used to import
system-like packages that are embedded into the binary.
This commit is contained in:
James Shubin
2024-02-22 19:02:33 -05:00
parent 9d8beb85d7
commit 70b5ed7067
7 changed files with 175 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ import (
etcdfs "github.com/purpleidea/mgmt/etcd/fs"
"github.com/purpleidea/mgmt/etcd/interfaces"
"github.com/purpleidea/mgmt/etcd/scheduler"
"github.com/purpleidea/mgmt/lang/embedded"
"github.com/purpleidea/mgmt/util"
)
@@ -191,6 +192,11 @@ func (obj *World) Fs(uri string) (engine.Fs, error) {
return obj.StandaloneFs, nil
}
if u.Scheme == embedded.Scheme {
path := strings.TrimPrefix(u.Path, "/") // expect a leading slash
return embedded.Lookup(path) // does not expect a leading slash
}
if u.Scheme != etcdfs.Scheme {
return nil, fmt.Errorf("unknown scheme: `%s`", u.Scheme)
}