util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

package util implements helper built-ins.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBase64Module

func NewBase64Module() *isopod.Module

NewBase64Module returns a base64 module.

func NewHTTPModule

func NewHTTPModule() *isopod.Module

NewHTTPModule returns new Isopod built-in module for HTTP calls. Supports these methods:

  • http.get - Performs HTTP GET call
  • http.post - Performs HTTP POST call
  • http.put - Performs HTTP PUT call
  • http.patch - Performs HTTP PATCH call
  • http.delete - Performs HTTP DELETE call

Args: url - required URL to send request to. headers - optional headers provided as Starlark dict. Values can be either

Starlark strings (for single value headers) or lists (for multiple
ones).

data - optional data sent in request body (take Starlark string).

Returns: Starlark string of response body. If response body is empty, returns starlark.None.

Errors out on non-2XX response codes.

func NewUUIDModule

func NewUUIDModule() *isopod.Module

NewUUIDModule returns a uuid module.

func ParseCommaSeparatedParams

func ParseCommaSeparatedParams(params string) (map[string]string, error)

ParseCommaSeparatedParams slipts params in the form of "foo=bar,baz=qux" in to a map {"foo": "bar", "baz": "qux"}

func Predeclared

func Predeclared() starlark.StringDict

Predeclared returns a starlark.StringDict containing predeclared modules from util:

  • base64 - Base64 encode/decode operations (RFC 4648).
  • uuid - UUID generate operations (RFC 4122).
  • http - HTTP calls.
  • struct - Starlark struct with to_json() support.

func StructFn

func StructFn(t *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

StructFn implements the built-in function that instantiates and extends the starlark struct to support to_json().

func ValueFromJSON

func ValueFromJSON(v interface{}) (starlark.Value, error)

ValueFromJSON converts JSON value to starlark.Value.

func ValueFromNestedMap

func ValueFromNestedMap(m map[string]interface{}) (starlark.Value, error)

ValueFromNestedMap converts nested JSON map oject to starlark.Value.

func WriteJSON

func WriteJSON(out *bytes.Buffer, v starlark.Value) error

WriteJSON marshals the starlark value to json blob.

Types

type Struct

type Struct struct {
	*starlarkstruct.Struct
}

Struct adds to_json attribute to the starlark struct.

func (*Struct) Attr

func (s *Struct) Attr(name string) (starlark.Value, error)

Attr implements starlark.HasAttrs.Attr.

Jump to

Keyboard shortcuts

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