Documentation
¶
Overview ¶
Package dataconv provides helper functions to convert between Starlark and Go types. It works like package starlight, but only supports common Starlark and Go types, and won't wrap any custom types or functions.
Index ¶
- func ConvertJSONStruct(v interface{}) starlark.Value
- func ConvertStruct(v interface{}, tagName string) starlark.Value
- func IsEmptyString(s starlark.String) bool
- func IsInterfaceNil(i interface{}) bool
- func Marshal(data interface{}) (v starlark.Value, err error)
- func MarshalStarlarkJSON(data starlark.Value, indent int) (string, error)
- func Unmarshal(x starlark.Value) (val interface{}, err error)
- func WrapModuleData(name string, data starlark.StringDict) func() (starlark.StringDict, error)
- type Marshaler
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertJSONStruct ¶ added in v0.0.7
ConvertJSONStruct converts a struct to a Starlark wrapper with JSON tag.
func ConvertStruct ¶ added in v0.0.7
ConvertStruct converts a struct to a Starlark wrapper.
func IsEmptyString ¶
IsEmptyString checks is a starlark string is empty ("" for a go string) starlark.String.String performs repr-style quotation, which is necessary for the starlark.Value contract but a frequent source of errors in API clients. This helper method makes sure it'll work properly
func IsInterfaceNil ¶
func IsInterfaceNil(i interface{}) bool
IsInterfaceNil returns true if the given interface is nil.
func Marshal ¶
Marshal converts Go values into Starlark types, like ToValue() of package starlight does. It only supports common Go types, won't wrap any custom types like Starlight does.
func MarshalStarlarkJSON ¶
MarshalStarlarkJSON marshals a starlark.Value into a JSON string. It first converts the starlark.Value into a Golang value, then marshals it into JSON.
func Unmarshal ¶
Unmarshal converts a starlark.Value into it's Golang counterpart, like FromValue() of package starlight does.
func WrapModuleData ¶ added in v0.0.7
func WrapModuleData(name string, data starlark.StringDict) func() (starlark.StringDict, error)
WrapModuleData wraps data from the given starlark.StringDict into a Starlark module loader, which can be used to load the module into a Starlark interpreter and accessed via `load("name", "data_key")`.
Types ¶
type Marshaler ¶
type Marshaler interface {
// MarshalStarlark marshal a custom type to Starlark object.
MarshalStarlark() (starlark.Value, error)
}
Marshaler is the interface use to marshal Starlark from custom types, i.e. Go to Starlark.
type Unmarshaler ¶
type Unmarshaler interface {
// UnmarshalStarlark unmarshal a Starlark object to custom type.
UnmarshalStarlark(starlark.Value) error
}
Unmarshaler is the interface use to unmarshal Starlark values to custom types, i.e. Starlark to Go.