go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit c084ded406f3a3433b0f4fe0dc69f8c04ab92b09
parent 194522fd95bd8323209c8ebc056567b87f59fe5e
Author: lash <dev@holbrook.no>
Date:   Mon, 17 Apr 2023 13:17:25 +0100

Enforce resource interface in profile resource constructor

Diffstat:
MREADME.md | 2+-
Mexamples/profile/main.go | 7+++++--
Mvm/runner.go | 3+--
3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -38,7 +38,7 @@ Original motivation was to create a simple templating renderer for USSD clients, * Breakpoints. * Key/value database reference example. -* Same-page catch with dedicated error string to prepend to template +* Dedicated error string to prepend to template (e.g. on catch) ## Opcodes diff --git a/examples/profile/main.go b/examples/profile/main.go @@ -35,7 +35,7 @@ type profileResource struct { haveEntered bool } -func newProfileResource(st *state.State, rs *resource.FsResource) *profileResource { +func newProfileResource(st *state.State, rs *resource.FsResource) resource.Resource { return &profileResource{ rs, st, @@ -113,7 +113,10 @@ func main() { st := state.NewState(3) rsf := resource.NewFsResource(scriptDir) - rs := newProfileResource(&st, &rsf) + rs, ok := newProfileResource(&st, &rsf).(*profileResource) + if !ok { + os.Exit(1) + } rs.AddLocalFunc("do_name_save", rs.nameSave) rs.AddLocalFunc("do_email_save", rs.emailSave) ca := cache.NewCache() diff --git a/vm/runner.go b/vm/runner.go @@ -72,7 +72,6 @@ func(vm *Vm) Run(b []byte, ctx context.Context) ([]byte, error) { panic(err) } if waitChange { - log.Printf("waitchange") _, err = vm.st.ResetFlag(state.FLAG_INMATCH) if err != nil { panic(err) @@ -463,7 +462,7 @@ func(vm *Vm) Render(ctx context.Context) (string, error) { return r, nil } -// retrieve data for key +// retrieve and cache data for key func(vm *Vm) refresh(key string, rs resource.Resource, ctx context.Context) (string, error) { fn, err := rs.FuncFor(key) if err != nil {