provider

package
v0.0.0-...-6d7b8bb Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2024 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cached

func Cached[T any](g func() (T, error), cache time.Duration) func() (T, error)

Cached wraps a getter with a cache

func NewBoolGetterFromConfig

func NewBoolGetterFromConfig(ctx context.Context, config Config) (func() (bool, error), error)

NewBoolGetterFromConfig creates a BoolGetter from config

func NewBoolSetterFromConfig

func NewBoolSetterFromConfig(ctx context.Context, param string, config Config) (func(bool) error, error)

NewBoolSetterFromConfig creates a BoolSetter from config

func NewBytesSetterFromConfig

func NewBytesSetterFromConfig(ctx context.Context, param string, config Config) (func([]byte) error, error)

NewBytesSetterFromConfig creates a BytesSetter from config

func NewCombinedProvider

func NewCombinedProvider(plugged, charging func() (bool, error)) *combinedProvider

NewCombinedProvider creates provider for OpenWB status converted from MQTT topics

func NewFloatGetterFromConfig

func NewFloatGetterFromConfig(ctx context.Context, config Config) (func() (float64, error), error)

NewFloatGetterFromConfig creates a FloatGetter from config

func NewFloatSetterFromConfig

func NewFloatSetterFromConfig(ctx context.Context, param string, config Config) (func(float642 float64) error, error)

NewFloatSetterFromConfig creates a FloatSetter from config

func NewIntGetterFromConfig

func NewIntGetterFromConfig(ctx context.Context, config Config) (func() (int64, error), error)

NewIntGetterFromConfig creates a IntGetter from config

func NewIntSetterFromConfig

func NewIntSetterFromConfig(ctx context.Context, param string, config Config) (func(int64) error, error)

NewIntSetterFromConfig creates a IntSetter from config

func NewStringGetterFromConfig

func NewStringGetterFromConfig(ctx context.Context, config Config) (func() (string, error), error)

NewStringGetterFromConfig creates a StringGetter from config

func NewStringSetterFromConfig

func NewStringSetterFromConfig(ctx context.Context, param string, config Config) (func(string) error, error)

NewStringSetterFromConfig creates a StringSetter from config

func ResetCached

func ResetCached()

func ResettableCached

func ResettableCached[T any](g func() (T, error), cache time.Duration) *cached[T]

ResettableCached wraps a getter with a cache. It returns a `Cacheable`. Instead of the cached getter, the `Get()` and `Reset()` methods are exposed.

Types

type Auth

type Auth struct {
	Type, User, Password string
}

Auth is the authorization config

type BoolProvider

type BoolProvider interface {
	BoolGetter() (func() (bool, error), error)
}

provider types

type Cacheable

type Cacheable[T any] interface {
	Get() (T, error)
	Reset()
}

Cacheable is the interface for a resettable cache

type Case

type Case struct {
	Case string
	Set  Config
}

type Config

type Config struct {
	Source string
	Other  map[string]any `mapstructure:",remain" yaml:",inline"`
}

Config is the general provider config

type FloatProvider

type FloatProvider interface {
	FloatGetter() (func() (float64, error), error)
}

provider types

type Getters

provider types

type Go

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

Go implements Go request provider

func (*Go) BoolGetter

func (p *Go) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from request

func (*Go) BoolSetter

func (p *Go) BoolSetter(param string) (func(bool) error, error)

BoolSetter sends bool request

func (*Go) FloatGetter

func (p *Go) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from request

func (*Go) FloatSetter

func (p *Go) FloatSetter(param string) (func(float64) error, error)

FloatSetter sends float request

func (*Go) IntGetter

func (p *Go) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from request

func (*Go) IntSetter

func (p *Go) IntSetter(param string) (func(int64) error, error)

IntSetter sends int request

func (*Go) StringGetter

func (p *Go) StringGetter() (func() (string, error), error)

StringGetter parses string from request

func (*Go) StringSetter

func (p *Go) StringSetter(param string) (func(string) error, error)

StringSetter sends string request

type HTTP

type HTTP struct {
	*request.Helper
	// contains filtered or unexported fields
}

HTTP implements HTTP request provider

func NewHTTP

func NewHTTP(log *util.Logger, method, uri string, insecure bool, cache time.Duration) *HTTP

NewHTTP create HTTP provider

func (HTTP) BoolGetter

func (p HTTP) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.

func (*HTTP) BoolSetter

func (p *HTTP) BoolSetter(param string) (func(bool) error, error)

BoolSetter sends bool request

func (HTTP) FloatGetter

func (p HTTP) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from exec result

func (*HTTP) FloatSetter

func (p *HTTP) FloatSetter(param string) (func(float64) error, error)

FloatSetter sends int request

func (HTTP) IntGetter

func (p HTTP) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from exec result

func (*HTTP) IntSetter

func (p *HTTP) IntSetter(param string) (func(int64) error, error)

IntSetter sends int request

func (*HTTP) StringGetter

func (p *HTTP) StringGetter() (func() (string, error), error)

StringGetter sends string request

func (*HTTP) StringSetter

func (p *HTTP) StringSetter(param string) (func(string) error, error)

StringSetter sends string request

func (*HTTP) WithAuth

func (p *HTTP) WithAuth(typ, user, password string) (*HTTP, error)

WithAuth adds authorized transport

func (*HTTP) WithBody

func (p *HTTP) WithBody(body string) *HTTP

WithBody adds request body

func (*HTTP) WithHeaders

func (p *HTTP) WithHeaders(headers map[string]string) *HTTP

WithHeaders adds request headers

func (*HTTP) WithPipeline

func (p *HTTP) WithPipeline(pipeline *pipeline.Pipeline) *HTTP

WithPipeline adds a processing pipeline

type IntProvider

type IntProvider interface {
	IntGetter() (func() (int64, error), error)
}

provider types

type Javascript

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

Javascript implements Javascript request provider

func (*Javascript) BoolGetter

func (p *Javascript) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from request

func (*Javascript) BoolSetter

func (p *Javascript) BoolSetter(param string) (func(bool) error, error)

BoolSetter sends bool request

func (*Javascript) FloatGetter

func (p *Javascript) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from request

func (*Javascript) FloatSetter

func (p *Javascript) FloatSetter(param string) (func(float64) error, error)

FloatSetter sends float request

func (*Javascript) IntGetter

func (p *Javascript) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from request

func (*Javascript) IntSetter

func (p *Javascript) IntSetter(param string) (func(int64) error, error)

IntSetter sends int request

func (*Javascript) StringGetter

func (p *Javascript) StringGetter() (func() (string, error), error)

StringGetter parses string from request

func (*Javascript) StringSetter

func (p *Javascript) StringSetter(param string) (func(string) error, error)

StringSetter sends string request

type Modbus

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

Modbus implements modbus RTU and TCP access

func (*Modbus) BoolGetter

func (m *Modbus) BoolGetter() (func() (bool, error), error)

BoolGetter implements BoolProvider

func (*Modbus) BoolSetter

func (m *Modbus) BoolSetter(param string) (func(bool) error, error)

BoolSetter implements SetBoolProvider

func (*Modbus) BytesSetter

func (m *Modbus) BytesSetter(_ string) (func([]byte) error, error)

BytesSetter implements SetBytesProvider

func (*Modbus) FloatGetter

func (m *Modbus) FloatGetter() (func() (f float64, err error), error)

FloatGetter implements func() (float64, error)

func (*Modbus) FloatSetter

func (m *Modbus) FloatSetter(_ string) (func(float64) error, error)

FloatSetter implements SetFloatProvider

func (*Modbus) IntGetter

func (m *Modbus) IntGetter() (func() (int64, error), error)

IntGetter implements IntProvider

func (*Modbus) IntSetter

func (m *Modbus) IntSetter(_ string) (func(int64) error, error)

IntSetter implements SetIntProvider

func (*Modbus) StringGetter

func (m *Modbus) StringGetter() (func() (string, error), error)

StringGetter implements StringProvider

type ModbusSunspec

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

ModbusSunspec implements modbus RTU and TCP access

func (*ModbusSunspec) FloatGetter

func (m *ModbusSunspec) FloatGetter() (func() (f float64, err error), error)

FloatGetter executes configured modbus read operation and implements func() (float64, error)

func (*ModbusSunspec) FloatSetter

func (m *ModbusSunspec) FloatSetter(_ string) (func(float64) error, error)

FloatSetter executes configured modbus write operation and implements SetFloatProvider

func (*ModbusSunspec) IntGetter

func (m *ModbusSunspec) IntGetter() (func() (int64, error), error)

IntGetter executes configured modbus read operation and implements IntProvider

func (*ModbusSunspec) IntSetter

func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error)

IntSetter executes configured modbus write operation and implements SetIntProvider

type Mqtt

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

Mqtt provider

func NewMqtt

func NewMqtt(log *util.Logger, client *mqtt.Client, topic string, timeout time.Duration) *Mqtt

NewMqtt creates mqtt provider for given topic

func (Mqtt) BoolGetter

func (p Mqtt) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.

func (*Mqtt) BoolSetter

func (m *Mqtt) BoolSetter(param string) (func(bool) error, error)

BoolSetter invokes script with parameter replaced by bool value

func (Mqtt) FloatGetter

func (p Mqtt) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from exec result

func (*Mqtt) FloatSetter

func (m *Mqtt) FloatSetter(param string) (func(float64) error, error)

FloatSetter publishes topic with parameter replaced by float value

func (Mqtt) IntGetter

func (p Mqtt) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from exec result

func (*Mqtt) IntSetter

func (m *Mqtt) IntSetter(param string) (func(int64) error, error)

IntSetter publishes topic with parameter replaced by int value

func (*Mqtt) StringGetter

func (m *Mqtt) StringGetter() (func() (string, error), error)

StringGetter creates handler for string from MQTT topic that returns cached value

func (*Mqtt) StringSetter

func (m *Mqtt) StringSetter(param string) (func(string) error, error)

StringSetter invokes script with parameter replaced by string value

func (*Mqtt) WithPayload

func (m *Mqtt) WithPayload(payload string) *Mqtt

WithPayload adds payload for setters

func (*Mqtt) WithPipeline

func (p *Mqtt) WithPipeline(pipeline *pipeline.Pipeline) *Mqtt

WithPipeline adds a processing pipeline

func (*Mqtt) WithRetained

func (m *Mqtt) WithRetained() *Mqtt

WithRetained adds retained flag for setters

func (*Mqtt) WithScale

func (m *Mqtt) WithScale(scale float64) *Mqtt

WithScale sets scaler for getters

type Prometheus

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

Prometheus provider

func NewPrometheus

func NewPrometheus(log *util.Logger, client api.Client, query string, timeout time.Duration) *Prometheus

func (*Prometheus) FloatGetter

func (p *Prometheus) FloatGetter() (func() (float64, error), error)

FloatGetter expects scalar value from query response as float

func (*Prometheus) IntGetter

func (p *Prometheus) IntGetter() (func() (int64, error), error)

IntGetter expects scalar value from query response as int

func (*Prometheus) Query

func (p *Prometheus) Query() (model.Value, error)

type Provider

type Provider interface{}

provider types

func NewCalcFromConfig

func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewCalcFromConfig creates calc provider

func NewCombinedFromConfig

func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewCombinedFromConfig creates combined provider

func NewConstFromConfig

func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewConstFromConfig creates const provider

func NewConvertFromConfig

func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewConvertFromConfig creates type conversion provider

func NewErrorFromConfig

func NewErrorFromConfig(other map[string]interface{}) (Provider, error)

NewErrorFromConfig creates error provider

func NewGoProviderFromConfig

func NewGoProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewGoProviderFromConfig creates a Go provider

func NewHTTPProviderFromConfig

func NewHTTPProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewHTTPProviderFromConfig creates a HTTP provider

func NewIgnoreFromConfig

func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewIgnoreFromConfig creates const provider

func NewJavascriptProviderFromConfig

func NewJavascriptProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewJavascriptProviderFromConfig creates a Javascript provider

func NewMapFromConfig

func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewMapFromConfig creates type conversion provider

func NewModbusFromConfig

func NewModbusFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewModbusFromConfig creates Modbus plugin

func NewModbusSunspecFromConfig

func NewModbusSunspecFromConfig(other map[string]interface{}) (Provider, error)

NewModbusSunspecFromConfig creates Modbus plugin

func NewMqttFromConfig

func NewMqttFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewMqttFromConfig creates Mqtt provider

func NewPrometheusFromConfig

func NewPrometheusFromConfig(other map[string]interface{}) (Provider, error)

func NewRandomFromConfig

func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewRandomFromConfig creates random provider

func NewSMAFromConfig

func NewSMAFromConfig(other map[string]interface{}) (Provider, error)

NewSMAFromConfig creates SMA provider

func NewScriptProviderFromConfig

func NewScriptProviderFromConfig(other map[string]interface{}) (Provider, error)

NewScriptProviderFromConfig creates a script provider.

func NewSequenceFromConfig

func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewSequenceFromConfig creates sequence provider

func NewSocketProviderFromConfig

func NewSocketProviderFromConfig(other map[string]interface{}) (Provider, error)

NewSocketProviderFromConfig creates a HTTP provider

func NewSwitchFromConfig

func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewSwitchFromConfig creates switch provider

func NewWatchDogFromConfig

func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error)

NewWatchDogFromConfig creates watchDog provider

type SMA

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

SMA provider

func (*SMA) FloatGetter

func (p *SMA) FloatGetter() (func() (float64, error), error)

FloatGetter creates handler for float64

func (*SMA) IntGetter

func (p *SMA) IntGetter() (func() (int64, error), error)

IntGetter creates handler for int64

type Script

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

Script implements shell script-based providers and setters

func NewScriptProvider

func NewScriptProvider(script string, timeout time.Duration, scale float64, cache time.Duration) (*Script, error)

NewScriptProvider creates a script provider. Script execution is aborted after given timeout.

func (Script) BoolGetter

func (p Script) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.

func (*Script) BoolSetter

func (p *Script) BoolSetter(param string) (func(bool) error, error)

BoolSetter invokes script with parameter replaced by bool value

func (Script) FloatGetter

func (p Script) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from exec result

func (Script) IntGetter

func (p Script) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from exec result

func (*Script) IntSetter

func (p *Script) IntSetter(param string) (func(int64) error, error)

IntSetter invokes script with parameter replaced by int value

func (*Script) StringGetter

func (p *Script) StringGetter() (func() (string, error), error)

StringGetter returns string from exec result. Only STDOUT is considered.

func (*Script) StringSetter

func (p *Script) StringSetter(param string) (func(string) error, error)

StringSetter returns a function that invokes a script with parameter by a string value

type SetBoolProvider

type SetBoolProvider interface {
	BoolSetter(param string) (func(bool) error, error)
}

provider types

type SetBytesProvider

type SetBytesProvider interface {
	BytesSetter(param string) (func([]byte) error, error)
}

provider types

type SetFloatProvider

type SetFloatProvider interface {
	FloatSetter(param string) (func(float64) error, error)
}

provider types

type SetIntProvider

type SetIntProvider interface {
	IntSetter(param string) (func(int64) error, error)
}

provider types

type SetStringProvider

type SetStringProvider interface {
	StringSetter(param string) (func(string) error, error)
}

provider types

type Socket

type Socket struct {
	*request.Helper
	// contains filtered or unexported fields
}

Socket implements websocket request provider

func (Socket) BoolGetter

func (p Socket) BoolGetter() (func() (bool, error), error)

BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.

func (Socket) FloatGetter

func (p Socket) FloatGetter() (func() (float64, error), error)

FloatGetter parses float from exec result

func (Socket) IntGetter

func (p Socket) IntGetter() (func() (int64, error), error)

IntGetter parses int64 from exec result

func (*Socket) StringGetter

func (p *Socket) StringGetter() (func() (string, error), error)

StringGetter sends string request

type StringProvider

type StringProvider interface {
	StringGetter() (func() (string, error), error)
}

provider types

type TimeoutHandler

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

TimeoutHandler is a wrapper for a Getter that times out after a given duration

func NewTimeoutHandler

func NewTimeoutHandler(ticker func() (string, error)) *TimeoutHandler

func (*TimeoutHandler) BoolGetter

func (h *TimeoutHandler) BoolGetter(p BoolProvider) (func() (bool, error), error)

func (*TimeoutHandler) FloatGetter

func (h *TimeoutHandler) FloatGetter(p FloatProvider) (func() (float64, error), error)

func (*TimeoutHandler) JsonGetter

func (h *TimeoutHandler) JsonGetter(p StringProvider) (func(any) error, error)

func (*TimeoutHandler) StringGetter

func (h *TimeoutHandler) StringGetter(p StringProvider) (func() (string, error), error)

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

Value is a cacheable value that can expire

func NewValue

func NewValue[T any](cache time.Duration) *Value[T]

func (*Value[T]) Get

func (v *Value[T]) Get() (T, error)

func (*Value[T]) Set

func (v *Value[T]) Set(val T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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