api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

api package provides HTTP interface to expose simulator parameters and to control them via simple REST API. It contains methods used by HTTP REST server to handle queries and HTTP client functions to generate those queries. Client methods are used in CLI to provide a way to control parameters outside of TCP server. HTTP is launched together with TCP simulator server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

Struct that keeps Device interface.

func NewHttpApiServer

func NewHttpApiServer(d Device) *Api

Create new instance of http server that fullfils Device interface. Server exposes REST API to control parameters and commands settings.

func (*Api) Serve

func (a *Api) Serve(ctx context.Context, addr string) error

Start HTTP server

type Client

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

Structure with client configuration.

func NewClient

func NewClient(url string) *Client

Create new Client isntance with configurable HTTP address.

func (*Client) GetCommandDelay

func (c *Client) GetCommandDelay(commandName string) (time.Duration, error)

Get command delay value via exposed REST API with HTTP Get query.

func (*Client) GetMismatch

func (c *Client) GetMismatch() (string, error)

Get mismatch string (message that is returned when ) via exposed REST API with Get query.

func (*Client) GetParameter

func (c *Client) GetParameter(param string) (string, error)

Get given parameter name from the simulator server via exposed REST API with HTTP GET query.

func (*Client) SetCommandDelay

func (c *Client) SetCommandDelay(commandName, value string) error

Set command delay via exposed REST aPI with HTTP Post query.

func (*Client) SetMismatch

func (c *Client) SetMismatch(value string) error

Set new mismatch message via exposed REST API with POST query.

func (*Client) SetParameter

func (c *Client) SetParameter(param, value string) error

Set given parameter with a specified value via exposed REST API with HTTP POST query.

func (*Client) Trigger

func (c *Client) Trigger(param string) error

Method to trigger returning parameter value on the TCP server side, uses HTTP Post query.

type Device

type Device interface {
	GetParameter(param string) (any, error)
	SetParameter(param string, val any) error
	GetCommandDelay(commandName string) (time.Duration, error)
	SetCommandDelay(commandName string, val string) error
	GetMismatch() []byte
	SetMismatch(mismatch string) error
	Trigger(param string) error
}

Interface provides methods to control parameters and commands settings via HTTP server.

Jump to

Keyboard shortcuts

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