car

package
v0.0.0-...-32d11fa Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Manage

func Manage(car *Car) node.Node

/////////////////////// C A R M A N A G E M E N T

Manage your car application using FreeCONF library according to the car.yang model file.

Manage is root handler from car.yang. i.e. module car { ... }

Types

type Car

type Car struct {
	Tire []*Tire

	Miles   float64
	Running bool

	// When the tires were last rotated
	LastRotation int64

	// Default speed value is in yang model file and free's your code
	// from hardcoded values, even if they are only default values
	// units milliseconds/mile
	Speed int

	// How fast to apply speed. Default it 1s or "miles per second"
	PollInterval time.Duration
	// contains filtered or unexported fields
}

//////////////////////// C A R - example application

This has nothing to do with FreeCONF, just an example application written in Go. that models a running car that can get flat tires when tires are worn.

func New

func New() *Car

func (*Car) NewTires

func (c *Car) NewTires()

func (*Car) OnUpdate

func (c *Car) OnUpdate(l CarListener) Subscription

OnUpdate to listen for car events like start, stop and flat tire

func (*Car) ReplaceTires

func (c *Car) ReplaceTires()

func (*Car) RotateTires

func (c *Car) RotateTires()

func (*Car) Start

func (c *Car) Start()

func (*Car) Stop

func (c *Car) Stop()

Stop will take up to poll_interval seconds to come to a stop

type CarListener

type CarListener func(UpdateEvent)

CarListener for receiving car update events

type Subscription

type Subscription interface {
	Close() error
}

Subscription is handle into a list.List that when closed will automatically remove item from list. Useful for maintaining a set of listeners that can easily remove themselves.

func NewSubscription

func NewSubscription(l *list.List, e *list.Element) Subscription

NewSubscription is used by subscription managers to give a token to caller the can close to unsubscribe to events

type Tire

type Tire struct {
	Pos  int
	Size string
	Flat bool
	Wear float64
	Worn bool
}

T I R E

func (*Tire) Replace

func (t *Tire) Replace()

type UpdateEvent

type UpdateEvent int

car event types

const (
	CarStarted UpdateEvent = iota + 1
	CarStopped
	FlatTire
)

func (UpdateEvent) String

func (e UpdateEvent) String() string

Jump to

Keyboard shortcuts

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