starlark_type

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmptyStarlarkString

func IsEmptyStarlarkString(s starlark.String) bool

IsEmptyStarlarkString 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 MarshalStarlark

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

MarshalStarlark turns go values into starlark types

func UnmarshalStarlark

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

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

func UnquoteStarlark

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

UnquoteStarlark unquotes a starlark string value

Types

type Index

type Index struct {
	Fields []string
	Unique bool
}

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 Request

type Request struct {
	AppName     string
	AppPath     string
	AppUrl      string
	PagePath    string
	PageUrl     string
	Method      string
	IsDev       bool
	IsPartial   bool
	PushEvents  bool
	HtmxVersion string
	Headers     http.Header
	RemoteIP    string
	UrlParams   map[string]string
	Form        url.Values
	Query       url.Values
	PostForm    url.Values
	Data        any
}

Request is a starlark.Value that represents an HTTP request. A Request is created from the Go http.Request and passed to the starlark handler function as it only argument. The Data field is updated with the handler's response and then the template evaluation is done with the same Request

func (Request) Attr

func (r Request) Attr(name string) (starlark.Value, error)

func (Request) AttrNames

func (r Request) AttrNames() []string

func (Request) Freeze

func (r Request) Freeze()

func (Request) Hash

func (r Request) Hash() (uint32, error)

func (Request) String

func (r Request) String() string

func (Request) Truth

func (r Request) Truth() starlark.Bool

func (Request) Type

func (r Request) Type() string

type StarlarkType

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

StarlarkType represents a Starlark type created from the schema type definition.

func NewStarlarkType

func NewStarlarkType(name string, data map[string]starlark.Value) *StarlarkType

func (*StarlarkType) Attr

func (s *StarlarkType) Attr(attr string) (starlark.Value, error)

func (*StarlarkType) AttrNames

func (s *StarlarkType) AttrNames() []string

func (*StarlarkType) Freeze

func (s *StarlarkType) Freeze()

func (*StarlarkType) Hash

func (s *StarlarkType) Hash() (uint32, error)

func (*StarlarkType) SetField

func (s *StarlarkType) SetField(name string, val starlark.Value) error

func (*StarlarkType) String

func (s *StarlarkType) String() string

func (*StarlarkType) Truth

func (s *StarlarkType) Truth() starlark.Bool

func (*StarlarkType) Type

func (s *StarlarkType) Type() string

func (*StarlarkType) UnmarshalStarlarkType

func (s *StarlarkType) UnmarshalStarlarkType() (any, error)

type StoreField

type StoreField struct {
	Name    string
	Type    TypeName
	Default any
}

type StoreInfo

type StoreInfo struct {
	Bytes []byte // The raw bytes for the schema.star file
	Types []StoreType
}

type StoreType

type StoreType struct {
	Name    string
	Fields  []StoreField
	Indexes []Index
}

type TypeBuilder

type TypeBuilder struct {
	Name   string
	Fields []StoreField
}

func (*TypeBuilder) CreateType

func (s *TypeBuilder) CreateType(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

type TypeName

type TypeName string
const (
	INT      TypeName = "INT"
	FLOAT    TypeName = "FLOAT"
	DATETIME TypeName = "DATETIME"
	STRING   TypeName = "STRING"
	BOOLEAN  TypeName = "BOOLEAN"
	LIST     TypeName = "LIST"
	DICT     TypeName = "DICT"
)

type TypeUnmarshaler

type TypeUnmarshaler interface {
	// UnmarshalStarlark unmarshals a starlark object to go object
	UnmarshalStarlarkType() (any, error)
}

Unmarshaler is the interface use to unmarshal starlark custom types.

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.

Jump to

Keyboard shortcuts

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