Documentation
¶
Overview ¶
Package internal contains types and utilities that are not part of the public API, and may change without notice. It should be only imported by the custom Starlark modules under starlet/lib folders, and not by the Starlet main package to avoid cyclic import.
Index ¶
- Constants
- func ExecModuleWithErrorTest(t *testing.T, name string, loader ModuleLoadFunc, script string, ...) (starlark.StringDict, error)
- func HereDoc(raw string) string
- func HereDocf(raw string, args ...interface{}) string
- 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)
- type FloatOrInt
- type Marshaler
- type ModuleLoadFunc
- type NumericValue
- type StringOrBytes
- type ThreadLoadFunc
- type Unmarshaler
Constants ¶
const StarletVersion = "v0.0.5"
StarletVersion is the current version of Starlet.
Variables ¶
This section is empty.
Functions ¶
func ExecModuleWithErrorTest ¶
func ExecModuleWithErrorTest(t *testing.T, name string, loader ModuleLoadFunc, script string, wantErr string) (starlark.StringDict, error)
ExecModuleWithErrorTest executes a Starlark script with a module loader and compares the error with the expected error.
func HereDocf ¶
HereDocf returns unindented and formatted string as here-document. Formatting is done as for fmt.Printf().
func IsEmptyString ¶ added in v0.0.2
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 ¶ added in v0.0.3
func IsInterfaceNil(i interface{}) bool
IsInterfaceNil returns true if the given interface is nil.
func Marshal ¶ added in v0.0.2
Marshal turns Go values into Starlark types. It only supports common Go types, won't wrap any custom types like Starlight does.
func MarshalStarlarkJSON ¶ added in v0.0.3
MarshalStarlarkJSON marshals a starlark.Value into a JSON string. It first converts the starlark.Value into a Golang value, then marshals it into JSON.
Types ¶
type FloatOrInt ¶
type FloatOrInt float64
FloatOrInt is an Unpacker that converts a Starlark int or float to Go's float64.
type Marshaler ¶ added in v0.0.2
type Marshaler interface {
// MarshalStarlark marshal a custom type to starlark object.
MarshalStarlark() (starlark.Value, error)
}
Marshaler is the interface use to marshal Starlark custom types.
type ModuleLoadFunc ¶
type ModuleLoadFunc func() (starlark.StringDict, error)
ModuleLoadFunc is a function that loads a Starlark module and returns the module's string dict.
type NumericValue ¶ added in v0.0.2
type NumericValue struct {
// contains filtered or unexported fields
}
NumericValue holds a Starlark numeric value and tracks its type. It can represent an integer or a float, and it prefers integers over floats.
func NewNumericValue ¶ added in v0.0.2
func NewNumericValue() *NumericValue
NewNumericValue creates and returns a new NumericValue.
func (*NumericValue) Add ¶ added in v0.0.2
func (n *NumericValue) Add(value starlark.Value) error
Add takes a Starlark Value and adds it to the NumericValue. It returns an error if the given value is neither an int nor a float.
func (*NumericValue) AsFloat ¶ added in v0.0.2
func (n *NumericValue) AsFloat() float64
AsFloat returns the float representation of the NumericValue.
func (*NumericValue) Value ¶ added in v0.0.2
func (n *NumericValue) Value() starlark.Value
Value returns the Starlark Value representation of the NumericValue.
type StringOrBytes ¶ added in v0.0.3
type StringOrBytes string
StringOrBytes is an Unpacker that converts a Starlark string or bytes to Go's string. It works because Go Starlark strings and bytes are both represented as Go strings.
func (StringOrBytes) GoString ¶ added in v0.0.3
func (p StringOrBytes) GoString() string
GoString returns the Go string representation of the StringOrBytes.
func (StringOrBytes) StarlarkString ¶ added in v0.0.3
func (p StringOrBytes) StarlarkString() starlark.String
StarlarkString returns the Starlark string representation of the StringOrBytes.
type ThreadLoadFunc ¶
ThreadLoadFunc is a function that loads a Starlark module by name, usually used by the Starlark thread.
func NewAssertLoader ¶
func NewAssertLoader(moduleName string, loader ModuleLoadFunc) ThreadLoadFunc
NewAssertLoader creates a Starlark thread loader that loads a module by name or asserts.star for testing.
type Unmarshaler ¶ added in v0.0.2
type Unmarshaler interface {
// UnmarshalStarlark unmarshal a starlark object to custom type.
UnmarshalStarlark(starlark.Value) error
}
Unmarshaler is the interface use to unmarshal Starlark custom types.