funcs

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FtoC = Func{
	Name: "FtoC",
	Fn: func(value interface{}) (interface{}, error) {
		f, err := utils.ConvertToFloat64(value)
		if err != nil {
			return nil, err
		}
		c := float64((f - 32.0) * 5.0 / 9.0)
		return c, nil
	},
}

FtoC is a Func which converts a value from degrees Fahrenheit to degrees Celsius.

Functions

func Register

func Register(funcs ...*Func) error

Register registers new funcs to the tracked funcs.

Types

type Func

type Func struct {
	// Name is the name of the function. This is how it is identified
	// and referenced.
	Name string

	// Fn is the function which will be called on the reading value.
	Fn func(value interface{}) (interface{}, error)
}

Func is a function that can be applied to a device reading.

func Get

func Get(name string) *Func

Get gets a Func by its name. If a func with the specified name is not found, nil is returned.

func GetBuiltins

func GetBuiltins() []*Func

GetBuiltins returns all the built-in Funcs supplied by the SDK.

func (*Func) Call

func (fn *Func) Call(value interface{}) (interface{}, error)

Call calls the function defined for the Func.

Jump to

Keyboard shortcuts

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