-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔌 serve: Support for pluggable evaluator (#28)
Support for pluggable evaluator, so that we can run jig with other scripting languages such as JS. Introduce Evaluator interface assuming we will add methods for scaffolding with "jig bones". This PR is a continuation of @alecthomas ' RFC: #25 Pull-Request: #28
- Loading branch information
1 parent
8ea14f9
commit 44ef52e
Showing
6 changed files
with
77 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package serve | ||
|
||
import ( | ||
"io/fs" | ||
|
||
"github.com/google/go-jsonnet" | ||
) | ||
|
||
type Evaluator interface { | ||
Evaluate(method, input string, vfs fs.FS) (output string, err error) | ||
} | ||
|
||
type EvaluatorFunc func(method, input string, vfs fs.FS) (output string, err error) | ||
|
||
func (ef EvaluatorFunc) Evaluate(method, input string, vfs fs.FS) (output string, err error) { | ||
return ef(method, input, vfs) | ||
} | ||
|
||
func JsonnetEvaluator() Evaluator { | ||
return EvaluatorFunc(func(method, input string, vfs fs.FS) (output string, err error) { | ||
vm := jsonnet.MakeVM() | ||
vm.TLACode("input", input) | ||
filename := method + ".jsonnet" | ||
b, err := fs.ReadFile(vfs, filename) | ||
if err != nil { | ||
return "", err | ||
} | ||
return vm.EvaluateAnonymousSnippet(filename, string(b)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters