Documentation
¶
Overview ¶
Package skycfg is an extension library for the Starlark language that adds support for constructing Protocol Buffer messages.
Index ¶
- func AsProtoMessage(v starlark.Value) (proto.Message, bool)
- func FlattenProtoList(list *starlark.List) ([]proto.Message, error)
- func FlattenStringList(list *starlark.List) ([]string, error)
- func NewProtoMessage(msg proto.Message) (starlark.Value, error)
- func NewProtoPackage(r unstableProtoRegistryV2, name string) starlark.Value
- func NewUnstableProtobufRegistryV2(r *protoregistry.Types) unstableProtoRegistryV2
- func UnstablePredeclaredModules(r unstableProtoRegistryV2) starlark.StringDict
- func UnstableProtoModule(r unstableProtoRegistryV2) starlark.Value
- type CommonOption
- type Config
- func (c *Config) Filename() string
- func (c *Config) Globals() starlark.StringDict
- func (c *Config) Locals() starlark.StringDict
- func (c *Config) Main(ctx context.Context, opts ...ExecOption) ([]proto.Message, error)
- func (c *Config) MainNonProtobuf(ctx context.Context, opts ...ExecOption) ([]string, error)
- func (c *Config) Tests() []*Test
- type ExecOption
- type FileReader
- type LoadCache
- type LoadOption
- type Test
- type TestOption
- type TestResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsProtoMessage ¶
AsProtoMessage returns a Protobuf message underlying the given Starlark value, which must have been created by NewProtoMessage(). Returns (_, false) if the value is not a valid message.
func FlattenProtoList ¶ added in v0.2.0
func FlattenStringList ¶ added in v0.2.0
func NewProtoMessage ¶
NewProtoMessage returns a Starlark value representing the given Protobuf message. It can be returned back to a proto.Message() via AsProtoMessage().
func NewProtoPackage ¶
NewProtoPackage returns a Starlark value representing the given Protobuf package. It can be added to global symbols when loading a Skycfg config file.
func NewUnstableProtobufRegistryV2 ¶ added in v0.1.1
func NewUnstableProtobufRegistryV2(r *protoregistry.Types) unstableProtoRegistryV2
func UnstablePredeclaredModules ¶
func UnstablePredeclaredModules(r unstableProtoRegistryV2) starlark.StringDict
UnstablePredeclaredModules returns a Starlark string dictionary with predeclared Skycfg modules which can be used in starlark.ExecFileOptions.
Takes in unstableProtoRegistry as param (if nil will use standard proto registry).
Currently provides these modules (see REAMDE for more detailed description):
- fail - interrupts execution and prints a stacktrace.
- hash - supports md5, sha1 and sha245 functions.
- json - marshals plain values (dicts, lists, etc) to JSON.
- proto - package for constructing Protobuf messages.
- struct - experimental Starlark struct support.
- yaml - same as "json" package but for YAML.
- url - utility package for encoding URL query string.
func UnstableProtoModule ¶ added in v0.1.1
Types ¶
type CommonOption ¶ added in v0.2.0
type CommonOption interface {
LoadOption
ExecOption
TestOption
}
A CommonOption is an option that can be applied to Load, Config.Main, and Test.Run.
func WithLogOutput ¶ added in v0.2.0
func WithLogOutput(w io.Writer) CommonOption
WithLogOutput changes the destination of print() function calls in Starlark code. If nil, os.Stderr will be used.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
A Config is a Skycfg config file that has been fully loaded and is ready for execution.
func (*Config) Globals ¶
func (c *Config) Globals() starlark.StringDict
Globals returns the set of variables in the Starlark global namespace, including any added to the config loader by WithGlobals().
func (*Config) Locals ¶
func (c *Config) Locals() starlark.StringDict
Locals returns the set of variables in the Starlark local namespace for the top-level module.
func (*Config) Main ¶
Main executes main() or a custom entry point function from the top-level Skycfg config module, which is expected to return either None or a list of Protobuf messages.
func (*Config) MainNonProtobuf ¶ added in v0.2.0
MainNonProtobuf executes main() or a custom entry point function from the top-level Skycfg config module, which is expected to return either None or a list of strings, and NOT protobuf. If the rendered entry point returns nested lists, then they are flattened. This is expected to be used for Skycfg files which do not return protobufs (e.g. stringified YAML) which is then passed downstream to other systems which process the string output.
type ExecOption ¶
type ExecOption interface {
// contains filtered or unexported methods
}
An ExecOption adjusts details of how a Skycfg config's main function is executed.
func WithEntryPoint ¶
func WithEntryPoint(name string) ExecOption
WithEntryPoint changes the name of the Skycfg function to execute.
func WithFlattenLists ¶ added in v0.1.1
func WithFlattenLists() ExecOption
WithFlattenLists flatten lists one layer deep ([1, [2,3]] -> [1, 2, 3])
func WithPositionalArgs ¶ added in v0.2.0
func WithPositionalArgs(args ...starlark.Value) ExecOption
WithPositionalArgs adds positional arguments in addition to ctx.
func WithVars ¶
func WithVars(vars starlark.StringDict) ExecOption
WithVars adds key:value pairs to the ctx.vars dict passed to main().
type FileReader ¶
type FileReader interface {
// Resolve parses the "name" part of load("name", "symbol") to a path. This
// is not required to correspond to a true path on the filesystem, but should
// be "absolute" within the semantics of this FileReader.
//
// fromPath will be empty when loading the root module passed to Load().
Resolve(ctx context.Context, name, fromPath string) (path string, err error)
// ReadFile reads the content of the file at the given path, which was
// returned from Resolve().
ReadFile(ctx context.Context, path string) ([]byte, error)
}
A FileReader controls how load() calls resolve and read other modules.
func FSFileReader ¶ added in v0.2.0
func FSFileReader(fsys fs.FS) FileReader
FSFileReader returns a FileReader that loads files from the given fs.FS. Path resolution on a FSFileReader is just path.Clean.
func LocalFileReader ¶
func LocalFileReader(root string) FileReader
LocalFileReader returns a FileReader that resolves and loads files from within a given filesystem directory. LocalFileReader expects paths in load() to always use '/' as the separator, regardless of the operating system's native path separator.
type LoadCache ¶ added in v0.2.0
type LoadCache struct {
// contains filtered or unexported fields
}
A LoadCache is an object that can be shared between several different calls to Load, in order to avoid loading the same skycfg file multiple times. See WithLoadCache.
Sharing a LoadCache is only meaningful if compatible [FileReader]s are used.
The zero LoadCache is empty and ready to use. A LoadCache must not be copied after first use. The same LoadCache is safe for use with concurrent Load calls.
type LoadOption ¶
type LoadOption interface {
// contains filtered or unexported methods
}
A LoadOption adjusts details of how Skycfg configs are loaded.
func WithFileOptions ¶ added in v0.2.0
func WithFileOptions(fileOpts *syntax.FileOptions) LoadOption
WithFileOptions changes the Starlark syntax options used when executing the Skycfg file. By default, we use syntax.LegacyFileOptions.
func WithFileReader ¶
func WithFileReader(r FileReader) LoadOption
WithFileReader changes the implementation of load() when loading a Skycfg config.
func WithGlobals ¶
func WithGlobals(globals starlark.StringDict) LoadOption
WithGlobals adds additional global symbols to the Starlark environment when loading a Skycfg config.
func WithLoadCache ¶ added in v0.2.0
func WithLoadCache(cache *LoadCache) LoadOption
WithLoadCache applies a given LoadCache for this call to Load. If a skycfg file has been loaded before on a call to Load with the same LoadCache, the cached value will be used instead of reloading the file.
func WithProtoRegistry ¶
func WithProtoRegistry(r unstableProtoRegistryV2) LoadOption
WithProtoRegistry is an EXPERIMENTAL and UNSTABLE option to override how Protobuf message type names are mapped to Go types.
type Test ¶
type Test struct {
// contains filtered or unexported fields
}
A Test is a test case, which is a skycfg function whose name starts with `test_`.
func (*Test) Run ¶
func (t *Test) Run(ctx context.Context, opts ...TestOption) (*TestResult, error)
Run actually executes a test. It returns a TestResult if the test completes (even if it fails) The error return value will only be non-nil if the test execution itself errors.
type TestOption ¶ added in v0.1.1
type TestOption interface {
// contains filtered or unexported methods
}
An TestOption adjusts details of how a Skycfg config's test functions are executed.
func WithTestVars ¶ added in v0.1.1
func WithTestVars(vars starlark.StringDict) TestOption
WithTestVars adds key:value pairs to the ctx.vars dict passed to tests
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
envoy
module
|
|
|
k8s
module
|
|
|
repl
module
|
|
|
wasm
module
|
|
|
Package debugger implements a simple interactive debugger for [starlark-go], aka go.starlark.net/starlark.
|
Package debugger implements a simple interactive debugger for [starlark-go], aka go.starlark.net/starlark. |
|
go
|
|
|
hashmodule
Package hashmodule defines a Starlark module of common hash functions.
|
Package hashmodule defines a Starlark module of common hash functions. |
|
parallelmodule
Package parallelmodule contains Starlark functions for running code in parallel.
|
Package parallelmodule contains Starlark functions for running code in parallel. |
|
protomodule
Package protomodule defines a Starlark module of Protobuf-related functions.
|
Package protomodule defines a Starlark module of Protobuf-related functions. |
|
urlmodule
Package urlmodule defines a Starlark module of URL-related functions.
|
Package urlmodule defines a Starlark module of URL-related functions. |
|
yamlmodule
Package yamlmodule defines a Starlark module of YAML-related functions.
|
Package yamlmodule defines a Starlark module of YAML-related functions. |
|
internal
|
|