routeros

package module
v2.0.0-...-1bbf141 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 11 Imported by: 19

README

RouterOS Client for the Go language

Go library for accessing Mikrotik devices using the RouterOS API.

Look in the examples directory to learn how to use this library: run, listen, tab.

API documentation is available at godoc.org.

To install it, run:

go get gopkg.in/routeros.v2

Documentation

Overview

Package routeros is a pure Go client library for accessing Mikrotik devices using the RouterOS API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a RouterOS API client.

func Dial

func Dial(address, username, password string) (*Client, error)

Dial connects and logs in to a RouterOS device.

func DialTLS

func DialTLS(address, username, password string, tlsConfig *tls.Config) (*Client, error)

DialTLS connects and logs in to a RouterOS device using TLS.

func DialTLSTimeout

func DialTLSTimeout(address, username, password string, tlsConfig *tls.Config, timeout time.Duration) (*Client, error)

DialTLSTimeout connects and logs in to a RouterOS device using TLS with timeout.

func DialTimeout

func DialTimeout(address, username, password string, timeout time.Duration) (*Client, error)

Dial connects and logs in to a RouterOS device.

func NewClient

func NewClient(rwc io.ReadWriteCloser) (*Client, error)

NewClient returns a new Client over rwc. Login must be called.

func (*Client) Async

func (c *Client) Async() <-chan error

Async starts asynchronous mode and returns immediately.

func (*Client) Close

func (c *Client) Close()

Close closes the connection to the RouterOS device.

func (*Client) Listen

func (c *Client) Listen(sentence ...string) (*ListenReply, error)

Listen simply calls ListenArgsQueue() with queueSize set to c.Queue.

func (*Client) ListenArgs

func (c *Client) ListenArgs(sentence []string) (*ListenReply, error)

ListenArgs simply calls ListenArgsQueue() with queueSize set to c.Queue.

func (*Client) ListenArgsQueue

func (c *Client) ListenArgsQueue(sentence []string, queueSize int) (*ListenReply, error)

ListenArgsQueue sends a sentence to the RouterOS device and returns immediately.

func (*Client) Login

func (c *Client) Login(username, password string) error

Login runs the /login command. Dial and DialTLS call this automatically.

func (*Client) Run

func (c *Client) Run(sentence ...string) (*Reply, error)

Run simply calls RunArgs().

func (*Client) RunArgs

func (c *Client) RunArgs(sentence []string) (*Reply, error)

RunArgs sends a sentence to the RouterOS device and waits for the reply.

type DeviceError

type DeviceError struct {
	Sentence *proto.Sentence
}

DeviceError records the sentence containing the error received from the device. The sentence may have Word !trap or !fatal.

func (*DeviceError) Error

func (err *DeviceError) Error() string

type ListenReply

type ListenReply struct {
	Done *proto.Sentence
	// contains filtered or unexported fields
}

ListenReply is the struct returned by the Listen*() functions. When the channel returned by Chan() is closed, Done is set to the RouterOS sentence that caused it to be closed.

func (*ListenReply) Cancel

func (l *ListenReply) Cancel() (*Reply, error)

Cancel sends a cancel command to the RouterOS device.

func (*ListenReply) Chan

func (l *ListenReply) Chan() <-chan *proto.Sentence

Chan returns a channel for receiving !re RouterOS sentences. To close the channel, call Cancel() on l.

func (*ListenReply) Err

func (a *ListenReply) Err() error

Err returns the first error that happened processing sentences with tag.

type Reply

type Reply struct {
	Re   []*proto.Sentence
	Done *proto.Sentence
}

Reply has all the sentences from a reply.

func (*Reply) String

func (r *Reply) String() string

type UnknownReplyError

type UnknownReplyError struct {
	Sentence *proto.Sentence
}

UnknownReplyError records the sentence whose Word is unknown.

func (*UnknownReplyError) Error

func (err *UnknownReplyError) Error() string

Directories

Path Synopsis
examples
run
tab

Jump to

Keyboard shortcuts

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