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 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 Config
- type ExecOption
- type FileReader
- 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 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.ExecFile.
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 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.
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 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 LocalFileReader ¶
func LocalFileReader(root string) FileReader
LocalFileReader returns a FileReader that resolves and loads files from within a given filesystem directory.
type LoadOption ¶
type LoadOption interface {
// contains filtered or unexported methods
}
A LoadOption adjusts details of how Skycfg configs are loaded.
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 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
|
|
wasm
Module
|
|
go
|
|
hashmodule
Package hashmodule defines a Starlark module of common hash functions.
|
Package hashmodule defines a Starlark module of common hash functions. |
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. |