lucirpc

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

README

lucirpc

An RPC client for LuCI.

This requires a little bit of setup on the OpenWrt device.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Boolean added in v0.0.6

func Boolean(value bool) *optionBoolean

Boolean constructs a new Option.

func Integer added in v0.0.6

func Integer(value int) *optionInteger

Integer constructs a new Option.

func ListString added in v0.0.6

func ListString(value []string) *optionListString

ListString constructs a new Option.

func String added in v0.0.6

func String(value string) *optionString

String constructs a new Option.

Types

type Client

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

func NewClient

func NewClient(
	ctx context.Context,
	scheme string,
	hostname string,
	port uint16,
	username string,
	password string,
) (*Client, error)

func (*Client) CommitChanges added in v0.0.2

func (c *Client) CommitChanges(
	ctx context.Context,
	config string,
) (bool, error)

func (*Client) CreateSection added in v0.0.2

func (c *Client) CreateSection(
	ctx context.Context,
	config string,
	sectionType string,
	section string,
	options Options,
) (bool, error)

func (*Client) DeleteSection added in v0.0.2

func (c *Client) DeleteSection(
	ctx context.Context,
	config string,
	section string,
) (bool, error)

func (*Client) GetSection

func (c *Client) GetSection(
	ctx context.Context,
	config string,
	section string,
) (Options, error)

func (*Client) ShowChanges added in v0.0.2

func (c *Client) ShowChanges(
	ctx context.Context,
	config string,
) ([][]string, error)

func (*Client) UpdateSection added in v0.0.2

func (c *Client) UpdateSection(
	ctx context.Context,
	config string,
	section string,
	options Options,
) (bool, error)

type Option added in v0.0.6

type Option interface {
	json.Marshaler
	json.Unmarshaler
	AsBoolean() (bool, error)
	AsInteger() (int, error)
	AsListString() ([]string, error)
	AsString() (string, error)
}

Option represents the different types of options that UCI supports. They can be parsed from/serialized to JSON using json.Unmarshal/json.Marshal, respectively. They can also attempt to be serialized to the underlying Go value using the `As*` methods.

To construct an Option, use one of Boolean, Integer, ListString, or String.

type OptionNotFoundError added in v0.0.6

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

OptionNotFoundError represents an error finding the specified option. It also communicates which options were searched.

func NewOptionNotFoundError added in v0.0.6

func NewOptionNotFoundError(
	option string,
	options []string,
) OptionNotFoundError

NewOptionNotFoundError constructs a new OptionNotFoundError. The `option` should be the option that wasn't found. The `options` should be the options that were searched.

func (OptionNotFoundError) Equal added in v0.0.6

func (OptionNotFoundError) Error added in v0.0.6

func (e OptionNotFoundError) Error() string

type OptionTypeMismatchError added in v0.0.6

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

OptionTypeMismatchError represents an error where the option was not the expected type.

func NewOptionTypeMismatchError added in v0.0.6

func NewOptionTypeMismatchError(
	expected string,
	actual string,
) OptionTypeMismatchError

NewOptionTypeMismatchError constructs a new OptionTypeMismatchError. It requires both the `actual` and `expected` types.

func (OptionTypeMismatchError) Equal added in v0.0.6

func (OptionTypeMismatchError) Error added in v0.0.6

func (e OptionTypeMismatchError) Error() string

type Options added in v0.0.6

type Options map[string]Option

Options are the actual UCI options for each section. The values can be booleans, integers, lists, and strings.

func (Options) GetBoolean added in v0.0.6

func (os Options) GetBoolean(option string) (bool, error)

GetBoolean attempts to find the bool for the given option.

The error could either be NewOptionNotFoundError, or one of the standard JSON errors.

func (Options) GetInteger added in v0.0.6

func (os Options) GetInteger(option string) (int, error)

GetInteger attempts to find the bool for the given option.

The error could either be NewOptionNotFoundError, or one of the standard JSON errors.

func (Options) GetListString added in v0.0.6

func (os Options) GetListString(option string) ([]string, error)

GetListString attempts to find the bool for the given option.

The error could either be NewOptionNotFoundError, or one of the standard JSON errors.

func (Options) GetString added in v0.0.6

func (os Options) GetString(option string) (string, error)

GetString attempts to find the bool for the given option.

The error could either be NewOptionNotFoundError, or one of the standard JSON errors.

func (*Options) UnmarshalJSON added in v0.0.6

func (os *Options) UnmarshalJSON(raw []byte) error

Jump to

Keyboard shortcuts

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