syringe

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builtin

type Builtin struct {
	Name  string
	Alias string
	Usage string
	// contains filtered or unexported fields
}

type Logger

type Logger interface {
	Print(v ...interface{})
}

Logger is an interface that Syringe uses for "log" statements.

type Opts

type Opts struct {
	Logger Logger // Used for "log" statements, defaults to https://pkg.go.dev/log
}

Opts are the options for New.

type Syringe

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

Syringe is the receiver of the template functions injector.

func New

func New(o *Opts) *Syringe

New returns an initialized Syringe.

func (*Syringe) Add

func (s *Syringe) Add(a, b interface{}) (interface{}, error)

Add adds two numbers.

func (*Syringe) AddByte added in v1.0.5

func (s *Syringe) AddByte(str string, val interface{}) (string, error)

AddByte adds a byte to a string and returns the expanded string.

func (*Syringe) AddElements

func (s *Syringe) AddElements(list []interface{}, els ...interface{}) []interface{}

AddElements is the builtin that adds elements to a list.

func (*Syringe) AliasesMap

func (s *Syringe) AliasesMap() template.FuncMap

AliasesMap returns a `template.FuncMap` that can be passed to text/template so that shorthand builtins can be used.

func (*Syringe) Assert

func (s *Syringe) Assert(cond bool, args ...interface{}) (string, error)

Assert is the builtin that ensures a condition.

func (*Syringe) Builtins

func (s *Syringe) Builtins() []Builtin

Builtins returns the list of builtin functions.

func (*Syringe) Contains added in v1.0.4

func (s *Syringe) Contains(haystack interface{}, needle interface{}) (bool, error)

Contains replaces HasElement or HasKey and offers substring matching.

func (*Syringe) Die

func (s *Syringe) Die(args ...interface{}) (string, error)

Die is the builtin that stops execution. If previous `Log` invocations occurred, then the the reason for stopping is logged, else, the reason is shown on `os.Stderr`.

func (*Syringe) Div

func (s *Syringe) Div(a, b interface{}) (interface{}, error)

Div divides two numbers.

func (*Syringe) Env

func (s *Syringe) Env(str string) string

Env is the builtin that fetches the value of an environment variable.

func (*Syringe) Expander

func (s *Syringe) Expander() string

Expander is the builtin returning the name of the expander program.

func (*Syringe) GetVal

func (s *Syringe) GetVal(m map[interface{}]interface{}, key interface{}) interface{}

GetVal is the builtin that returns a value from a map given a key, or "".

func (*Syringe) HasElement

func (s *Syringe) HasElement(list []interface{}, el interface{}) bool

HasElement is the builtin that checks whether a list contains an element. Deprecated: use Contains.

func (*Syringe) HasKey

func (s *Syringe) HasKey(m map[interface{}]interface{}, key interface{}) bool

HasKey is the builtin that checks whether a map contains a key. Deprecated: use Contains.

func (*Syringe) IndexOf

func (s *Syringe) IndexOf(list []interface{}, el interface{}) int

IndexOf returns the index of an element in a list, or -1.

func (*Syringe) IsFloat

func (s *Syringe) IsFloat(i interface{}) bool

IsFloat is the builtin that evaluates to `true` when its argument is a floating point number.

func (*Syringe) IsInt

func (s *Syringe) IsInt(i interface{}) bool

IsInt is the builtin that evaluates to `true` when its argument is an integer.

func (*Syringe) IsList

func (s *Syringe) IsList(i interface{}) bool

IsList is the builtin that evaluates to `true` when its argument is a list.

func (*Syringe) IsMap

func (s *Syringe) IsMap(i interface{}) bool

IsMap is the builtin that evaluates to `true` when its argument is a map.

func (*Syringe) IsNumber

func (s *Syringe) IsNumber(i interface{}) bool

IsNumber is the builtin that evaluates to `true` when its argument is a number (int or float).

func (*Syringe) List

func (s *Syringe) List(args ...interface{}) []interface{}

List is the builtin that returns a list.

func (*Syringe) Log

func (s *Syringe) Log(args ...interface{}) string

Log is the builtin that logs information using the `log.Print` function.

func (*Syringe) Loop

func (s *Syringe) Loop(a, b int) <-chan int

Loop is like a list of increasing ints.

func (*Syringe) Map

func (s *Syringe) Map(args ...interface{}) map[interface{}]interface{}

Map is the builtin that returns a map.

func (*Syringe) Mul

func (s *Syringe) Mul(a, b interface{}) (interface{}, error)

Mul multiplies two numbers.

func (*Syringe) SetKeyVal

func (s *Syringe) SetKeyVal(m map[interface{}]interface{}, key, val interface{}) string

SetKeyVal is the builtin that sets a value for a key in a map, or adds it.

func (*Syringe) Strcat added in v1.0.3

func (s *Syringe) Strcat(args ...interface{}) string

Strcat returns a string where all arguments are concatenated.

func (*Syringe) Sub

func (s *Syringe) Sub(a, b interface{}) (interface{}, error)

Sub subtracts two numbers.

func (*Syringe) Type

func (s *Syringe) Type(i interface{}) (string, error)

Type is the builtin to return the type of something as "int", "float", etc.

func (*Syringe) Version

func (s *Syringe) Version() string

Version is the builtin returning the version of the expander program.

Jump to

Keyboard shortcuts

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