21 lines
556 B
Go
21 lines
556 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"sea-vhost/internal/nodefiles"
|
|
)
|
|
|
|
func (s *Projects) WithFileOpener(open func(context.Context, string) (*nodefiles.Root, error)) *Projects {
|
|
s.fileOpener = open
|
|
return s
|
|
}
|
|
func (s *Projects) OpenFiles(ctx context.Context, root string) (*nodefiles.Root, error) {
|
|
if s.fileOpener != nil {
|
|
return s.fileOpener(ctx, root)
|
|
}
|
|
return nodefiles.New(ctx, filepath.Base(root), func(_ context.Context, q nodefiles.Request) (nodefiles.Response, error) {
|
|
return nodefiles.Execute(root, q), nil
|
|
}), nil
|
|
}
|