hbcfg

package
v3.0.0-rc21 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hbcfg provides helpers to create hb drivers from configuration

candidate hb drivers needs to be registered before use

Usage example on hb unicast driver

import "opensvc.com/opensvc/core/hbcfg"
type (
	T struct {hbcfg.T} // Concrete object that implement Configure
	tx struct {...}    // concrete object that implement Transmitter
	tx struct {...}    // concrete object that implement Receiver
)

func New() hbcfg.Confer {
	var i interface{} = &T{}
	return i.(hbcfg.Confer)
}

// register unicast hb driver
func init() { hbcfg.Register("unicast", NewConfer) }

func NewTx(..., timeout time.Duration) *tx { ... }
func NewRx(..., timeout time.Duration) *rx { ... }

func (t *T) Configure(ctx context.Context) {
	...
	timeout := t.GetDuration("timeout", 5*time.Second)
	rx := NewRx(..., timeout)
	tx := NewTx(..., timeout)
	t.SetTx(rx)
	t.SetRx(tx)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Driver

func Driver(driverName string) func() Confer

func Register

func Register(driverName string, fn func() Confer)

Register function register a new hb driver confer

Types

type Confer

type Confer interface {
	TConfer

	// Configure prepare Receiver and Transmitter concrete objects
	// composed hb driver struct have to implement Configure
	Configure(ctx context.Context)
}

Confer is the interface a hb driver has to implement type struct composed on T have to implement Configure to satisfy Confer

func New

func New(name string, config *xconfig.T) Confer

type T

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

T struct implement TConfer

func (*T) Config

func (t *T) Config() *xconfig.T

func (*T) GetBool

func (t *T) GetBool(s string) bool

func (*T) GetDuration

func (t *T) GetDuration(s string, defaultValue time.Duration) time.Duration

func (*T) GetInt

func (t *T) GetInt(s string) int

func (*T) GetIntAs

func (t *T) GetIntAs(s, impersonate string) int

func (*T) GetString

func (t *T) GetString(s string) string

func (*T) GetStringAs

func (t *T) GetStringAs(s, impersonate string) string

func (*T) GetStrings

func (t *T) GetStrings(s string) []string

func (*T) Interval

func (t *T) Interval() time.Duration

func (T) Name

func (t T) Name() string

func (*T) Nodes

func (t *T) Nodes() []string

func (*T) Rx

func (t *T) Rx() hbtype.Receiver

func (*T) SetConfig

func (t *T) SetConfig(c *xconfig.T)

func (*T) SetDriver

func (t *T) SetDriver(driver string)

func (*T) SetInterval

func (t *T) SetInterval(interval time.Duration)

func (*T) SetName

func (t *T) SetName(name string)

func (*T) SetNodes

func (t *T) SetNodes(nodes []string)

func (*T) SetRx

func (t *T) SetRx(rx hbtype.Receiver)

func (*T) SetSignature

func (t *T) SetSignature(s string)

SetSignature set a string that identifies config details

func (*T) SetTimeout

func (t *T) SetTimeout(timeout time.Duration)

func (*T) SetTx

func (t *T) SetTx(tx hbtype.Transmitter)

func (*T) Signature

func (t *T) Signature() string

Signature returns the string identification of config details

func (*T) Timeout

func (t *T) Timeout() time.Duration

func (*T) Tx

func (t *T) Tx() hbtype.Transmitter

func (T) Type

func (t T) Type() string

type TConfer

type TConfer interface {
	Name() string
	Type() string
	Config() *xconfig.T
	Interval() time.Duration
	Timeout() time.Duration
	Tx() hbtype.Transmitter
	Rx() hbtype.Receiver
	Nodes() []string
	Signature() string

	SetName(string)
	SetDriver(string)
	SetConfig(*xconfig.T)
	SetRx(receiver hbtype.Receiver)
	SetTx(transmitter hbtype.Transmitter)
	SetInterval(time.Duration)
	SetTimeout(time.Duration)
	SetNodes([]string)
	SetSignature(string)
}

TConfer interface hold getter and setter for hb configuration T struct implement TConfer

Jump to

Keyboard shortcuts

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