vise/resource/resource.go

68 lines
1.9 KiB
Go
Raw Permalink Normal View History

2023-03-31 11:52:04 +02:00
package resource
2023-03-31 11:59:55 +02:00
import (
"context"
)
type Result struct {
Content string
FlagSet []uint32
FlagReset []uint32
}
// EntryFunc is a function signature for retrieving value for a key
type EntryFunc func(sym string, input []byte, ctx context.Context) (Result, error)
type CodeFunc func(sym string) ([]byte, error)
type TemplateFunc func(sym string) (string, error)
type FuncForFunc func(sym string) (EntryFunc, error)
2023-03-31 11:52:04 +02:00
// Resource implementation are responsible for retrieving values and templates for symbols, and can render templates from value dictionaries.
type Resource interface {
GetTemplate(sym string) (string, error) // Get the template for a given symbol.
2023-04-01 11:58:02 +02:00
GetCode(sym string) ([]byte, error) // Get the bytecode for the given symbol.
2023-04-06 13:08:30 +02:00
FuncFor(sym string) (EntryFunc, error) // Resolve symbol content point for.
2023-03-31 11:52:04 +02:00
}
type MenuResource struct {
sinkValues []string
codeFunc CodeFunc
templateFunc TemplateFunc
funcFunc FuncForFunc
}
2023-04-08 11:20:34 +02:00
// NewMenuResource creates a new MenuResource instance.
func NewMenuResource() *MenuResource {
return &MenuResource{}
}
2023-04-08 11:20:34 +02:00
// WithCodeGetter sets the code symbol resolver method.
func(m *MenuResource) WithCodeGetter(codeGetter CodeFunc) *MenuResource {
m.codeFunc = codeGetter
return m
}
2023-04-08 11:20:34 +02:00
// WithEntryGetter sets the content symbol resolver getter method.
func(m *MenuResource) WithEntryFuncGetter(entryFuncGetter FuncForFunc) *MenuResource {
m.funcFunc = entryFuncGetter
return m
}
2023-04-08 11:20:34 +02:00
// WithTemplateGetter sets the template symbol resolver method.
func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResource {
m.templateFunc = templateGetter
return m
2023-04-03 10:11:44 +02:00
}
func(m *MenuResource) FuncFor(sym string) (EntryFunc, error) {
return m.funcFunc(sym)
}
func(m *MenuResource) GetCode(sym string) ([]byte, error) {
return m.codeFunc(sym)
}
func(m *MenuResource) GetTemplate(sym string) (string, error) {
return m.templateFunc(sym)
}