Documentation
¶
Overview ¶
Package startype provides type conversion, and other utilities, between Go types and Starlark types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoStructToStringDict ¶
func GoStructToStringDict(gostruct interface{}) (starlark.StringDict, error)
GoStructToStringDict is a helper func that converts a Go struct type to starlark.StringDict.
Types ¶
type GoValue ¶
type GoValue struct {
// contains filtered or unexported fields
}
GoValue represents an inherent Go value which can be converted to a Starlark value/type
func Go ¶
func Go(val interface{}) *GoValue
Go wraps a Go value into GoValue so that it can be converted to a Starlark value.
func (*GoValue) Starlark ¶
Starlark translates Go value to a starlark.Value value using the following type mapping:
bool -- starlark.Bool int{8,16,32,64} -- starlark.Int uint{8,16,32,64} -- starlark.Int float{32,64} -- starlark.Float string -- starlark.String []T, [n]T -- starlark.Tuple map[K]T -- *starlark.Dict
The specified Starlark value must be provided as a pointer to the target Starlark type.
Example:
num := 64 var starInt starlark.Int Go(num).Starlark(&starInt)
For starlark.List and starlark.Set refer to their respective namesake methods.
func (*GoValue) StarlarkList ¶
StarlarkList converts a slice of Go values to a starlark.Tuple, then converts that tuple into a starlark.List
func (*GoValue) StarlarkSet ¶
StarlarkSet converts a slice of Go values to a starlark.Tuple, then converts that tuple into a starlark.Set
type KwargsValue ¶ added in v0.0.2
type KwargsValue struct {
// contains filtered or unexported fields
}
func Kwargs ¶ added in v0.0.2
func Kwargs(kwargs []starlark.Tuple) *KwargsValue
Kwargs starts the conversion of a Starlark kwargs (keyword args) value to a Go struct. The function uses annotated fields on the struct to describe the keyword argument mapping as:
var Param struct { OutputFile string `name:"output_file" optional:"true"` SourcePaths []string `name:"output_path"` }
The struct can be mapped to the following keyword args:
kwargs := []starlark.Tuple{ {starlark.String("output_file"), starlark.String("/tmp/out.tar.gz")}, {starlark.String("source_paths"), starlark.NewList([]starlark.Value{starlark.String("/tmp/myfile")})}, }
Example ¶
Kwargs(kwargs).Go(&Param)
Supported annotation: `name:"arg_name" required:"true|false" (default false)`
func (*KwargsValue) Go ¶ added in v0.0.2
func (v *KwargsValue) Go(gostruct any) error