util

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMalformattedKwarg occurs when a keyword argument passed to a starlark function is malformatted.
	ErrMalformattedKwarg = errors.New("malformatted keyword argument for method call")

	// ErrMissingKwarg occurs when a keyword argument is missing from a starlark function call.
	ErrMissingKwarg = errors.New("missing keyword argument for method call")

	// ErrMissingArg occurs when an argument is missing from a starlark function call.
	ErrMissingArg = errors.New("missing argument for method call")

	// ErrInvalidArgType occurs when an argument provided to a starlark function call has the wrong type.
	ErrInvalidArgType = errors.New("invalid argument type provided to method")

	// ErrMissingLibrary occurs when attempting to load a library that doesn't exist.
	ErrMissingLibrary = errors.New("could not find library to load")

	// ErrInvalidTypeConversion occurs when converting a golang type to a starlark.Value fails.
	ErrInvalidTypeConversion = errors.New("could not convert golang value to starlark.Value")

	// ErrInvalidKwarg occurs when a user incorrectly passes a kwarg to a starlark function
	ErrInvalidKwarg = errors.New("invalid kwarg was passed to the method")
)

Functions

func AnnotateError

func AnnotateError(err error) string

AnnotateError error with detail info

func AsString

func AsString(x starlark.Value) (string, error)

AsString unquotes a starlark string value

func ConvertToStarlark

func ConvertToStarlark(value interface{}) (starlark.Value, error)

ConvertToStarlark provides an exported function for converting starlark values

func DecorateError

func DecorateError(thread *starlark.Thread, err error) error

DecorateError decorate all error with starlark detail

func EnsureWorkdir

func EnsureWorkdir(jobid string) string

func IsEmptyString

func IsEmptyString(s starlark.String) bool

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 Marshal

func Marshal(data interface{}) (v starlark.Value, err error)

Marshal turns go values into starlark types

func Unmarshal

func Unmarshal(x starlark.Value) (val interface{}, err error)

Unmarshal decodes a starlark.Value into it's golang counterpart

Types

type ArgParser

type ArgParser struct {
	ArgParserInterface
	// contains filtered or unexported fields
}

func GetParser

func GetParser(args starlark.Tuple, kwargs []starlark.Tuple) (*ArgParser, error)

func (*ArgParser) GetBool

func (parser *ArgParser) GetBool(index int) (bool, error)

func (*ArgParser) GetBoolByName

func (parser *ArgParser) GetBoolByName(kwarg string) (bool, error)

func (*ArgParser) GetInt

func (parser *ArgParser) GetInt(index int) (int64, error)

func (*ArgParser) GetIntByName

func (parser *ArgParser) GetIntByName(kwarg string) (int64, error)

func (*ArgParser) GetList

func (parser *ArgParser) GetList(index int) ([]interface{}, error)

func (*ArgParser) GetListByName

func (parser *ArgParser) GetListByName(kwarg string) ([]interface{}, error)

func (*ArgParser) GetParam

func (parser *ArgParser) GetParam(index int) (starlark.Value, error)

func (*ArgParser) GetParamIndex

func (parser *ArgParser) GetParamIndex(kwarg string) (int, error)

func (*ArgParser) GetString

func (parser *ArgParser) GetString(index int) (string, error)

func (*ArgParser) GetStringByName

func (parser *ArgParser) GetStringByName(kwarg string) (string, error)

func (*ArgParser) RestrictKwargs

func (parser *ArgParser) RestrictKwargs(kwargs ...string) error

type ArgParserInterface

type ArgParserInterface interface {
	RestrictKwargs(kwargs ...string) error

	GetParam(index int) (starlark.Value, error)

	GetString(index int) (string, error)
	GetStringByName(name string) (string, error)

	GetInt(index int) (int64, error)
	GetIntByName(name string) (int64, error)

	GetBool(index int) (bool, error)
	GetBoolByName(kwarg string) (bool, error)
}

ArgParser easy parse starlark args and kwargs

type ErrIncorrectType

type ErrIncorrectType struct {
	// contains filtered or unexported fields
}

func (ErrIncorrectType) Error

func (eit ErrIncorrectType) Error() string

type ErrUnhashable

type ErrUnhashable string

func (ErrUnhashable) Error

func (err ErrUnhashable) Error() string

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 custom types.

type Retval

type Retval interface{}

func WithError

func WithError(val Retval, err error) Retval

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 custom types.

Directories

Path Synopsis
Package replacecr defines a wrapper for replacing solo carriage return characters (\r) with carriage-return + line feed (\r\n)
Package replacecr defines a wrapper for replacing solo carriage return characters (\r) with carriage-return + line feed (\r\n)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL