admin

package
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: Apache-2.0 Imports: 20 Imported by: 28

Documentation

Index

Constants

View Source
const APIIndentation = "  "

APIIndentation is a single indentation to be used in HumanReadable calls on API entries

Variables

View Source
var (
	// ErrNotImplemented is an API error when the call is not implemented
	ErrNotImplemented = errors.New("Not Implemented")

	// ErrNotFound is an API error when the requested information was not found
	ErrNotFound = errors.New("Not Found")
)
View Source
var APINull = apiNull{}

APINull represents a null value

View Source
var (

	// DefaultAdminBind is the default bind address to use when admin is enabled
	// and can be modified during init()
	DefaultAdminBind = "tcp:127.0.0.1:12345"
)

Functions

This section is empty.

Types

type APIArray

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

APIArray represents an array of entries in the API accessible through a primary key

func (*APIArray) AddEntry

func (a *APIArray) AddEntry(key string, entry APINavigatable)

AddEntry a new array entry

func (*APIArray) Call

func (a *APIArray) Call(params url.Values) (string, error)

Call an API

func (*APIArray) Get

func (a *APIArray) Get(path string) (APINavigatable, error)

Get returns an entry using it's primary key name or row number

func (*APIArray) HumanReadable

func (a *APIArray) HumanReadable(indent string) ([]byte, error)

HumanReadable returns the APIArray as a string

func (*APIArray) MarshalJSON

func (a *APIArray) MarshalJSON() ([]byte, error)

MarshalJSON returns the APIArray in JSON form

func (*APIArray) RemoveEntry

func (a *APIArray) RemoveEntry(key string)

RemoveEntry removes an array entry

func (*APIArray) Update

func (a *APIArray) Update() error

Update ensures the data we have is up to date - should be overriden by users if required to keep the contents up to date on each request Default behaviour is to update each of the array entries

type APICallbackEntry

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

APICallbackEntry is an entry that provides an API callback

func NewAPICallbackEntry

func NewAPICallbackEntry(f APICallbackFunc) *APICallbackEntry

NewAPICallbackEntry creates a new APICallbackEntry from an APICallbackFunc

func (*APICallbackEntry) Call

func (c *APICallbackEntry) Call(values url.Values) (string, error)

Call runs the callback function

func (*APICallbackEntry) Get

func (c *APICallbackEntry) Get(path string) (APINavigatable, error)

Get always returns nil for an APICallbackEntry

func (*APICallbackEntry) HumanReadable

func (c *APICallbackEntry) HumanReadable(indent string) ([]byte, error)

HumanReadable returns the APICallbackEntry as a string

func (*APICallbackEntry) MarshalJSON

func (c *APICallbackEntry) MarshalJSON() ([]byte, error)

MarshalJSON returns the APICallbackEntry in JSON form

func (*APICallbackEntry) Update

func (c *APICallbackEntry) Update() error

Update does nothing for an APICallbackEntry

type APICallbackFunc

type APICallbackFunc func(url.Values) (string, error)

APICallbackFunc is a function that can be called by the API

type APIDataEntry

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

APIDataEntry wraps an APIEncodable so it can be used as an APINavigatable It stubs the navigation methods so they are no-ops

func NewAPIDataEntry

func NewAPIDataEntry(a APIEncodable) *APIDataEntry

NewAPIDataEntry creates a new APIDataEntry from an APIEncodable

func (*APIDataEntry) Call

func (d *APIDataEntry) Call(url.Values) (string, error)

Call always returns ErrNotImplemented for an APIDataEntry

func (*APIDataEntry) Get

func (d *APIDataEntry) Get(path string) (APINavigatable, error)

Get always returns nil for an APIDataEntry

func (*APIDataEntry) HumanReadable

func (d *APIDataEntry) HumanReadable(indent string) ([]byte, error)

HumanReadable returns the APIDataEntry as a string

func (*APIDataEntry) MarshalJSON

func (d *APIDataEntry) MarshalJSON() ([]byte, error)

MarshalJSON returns the APIDataEntry in JSON form

func (*APIDataEntry) Update

func (d *APIDataEntry) Update() error

Update does nothing for an APIDataEntry

type APIEncodable

type APIEncodable interface {
	// HumanReadable returns the entry as a string in human-readable form
	// If it contains multiple lines, it should prefix each line with the indent
	// string passes to it. If the call to HumanReadable needs to recurse into
	// another HumanReadable call it should add APIIndentation to the indent
	// string, and check the returned string for new lines and render accordingly
	HumanReadable(indent string) ([]byte, error)
}

APIEncodable is an encodable entry in the API, which can be a navigatable entry or just a piece of data

type APIFloat

type APIFloat float64

APIFloat represents a floating point number in the API

func (APIFloat) HumanReadable

func (f APIFloat) HumanReadable(string) ([]byte, error)

HumanReadable returns the APIFloat as a string

type APIKeyValue

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

APIKeyValue represents a set of data

func (*APIKeyValue) Call

func (d *APIKeyValue) Call(params url.Values) (string, error)

Call an API

func (*APIKeyValue) Get

Get always returns nil for an APIKeyValue as it is not navigatable

func (*APIKeyValue) HumanReadable

func (d *APIKeyValue) HumanReadable(indent string) ([]byte, error)

HumanReadable returns the APIKeyValue as a string

func (*APIKeyValue) MarshalJSON

func (d *APIKeyValue) MarshalJSON() ([]byte, error)

MarshalJSON returns the APIKeyValue data in JSON form

func (*APIKeyValue) RemoveEntry

func (d *APIKeyValue) RemoveEntry(key string, entry APIEncodable)

RemoveEntry removes a data entry

func (*APIKeyValue) SetEntry

func (d *APIKeyValue) SetEntry(key string, entry APIEncodable)

SetEntry sets a new data entry

func (*APIKeyValue) Update

func (d *APIKeyValue) Update() error

Update ensures the data we have is up to date - should be overriden by users if required to keep the contents up to date on each request

type APINavigatable

type APINavigatable interface {
	APIEncodable

	// Get returns the child entry with the requested name, or nil there are no
	// children
	Get(name string) (APINavigatable, error)

	// Call happens in response to a POST request
	Call(params url.Values) (string, error)

	// Update updates the entry data
	Update() error
}

APINavigatable is a navigatable entry in the API

type APINode

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

APINode acts like a directory in the API, containing mappings from names to status information of various types

func (*APINode) Call

func (n *APINode) Call(url.Values) (string, error)

Call an API

func (*APINode) Get

func (n *APINode) Get(path string) (APINavigatable, error)

Get the child entry with the specified name

func (*APINode) HumanReadable

func (n *APINode) HumanReadable(indent string) ([]byte, error)

HumanReadable returns the entire path structures in human-readable form

func (*APINode) MarshalJSON

func (n *APINode) MarshalJSON() ([]byte, error)

MarshalJSON returns the entire path structures in JSON form

func (*APINode) RemoveEntry

func (n *APINode) RemoveEntry(path string)

RemoveEntry removes a path entry

func (*APINode) SetEntry

func (n *APINode) SetEntry(path string, entry APINavigatable)

SetEntry adds a new path entry with the given name

func (*APINode) Update

func (n *APINode) Update() error

Update ensures the data we have is up to date - should be overriden by users if required to keep the contents up to date on each request Default behaviour is to update each of the navigatable entries

type APINumber

type APINumber int64

APINumber represents an integer number in the API

func (APINumber) HumanReadable

func (n APINumber) HumanReadable(string) ([]byte, error)

HumanReadable returns the APINumber as a string

type APIString

type APIString string

APIString represents a string in the API

func (APIString) HumanReadable

func (s APIString) HumanReadable(string) ([]byte, error)

HumanReadable returns the APIString as a string

type Client

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

Client provides an interface for accessing the REST API with pretty responses

func NewClient

func NewClient(adminConnect string) (*Client, error)

NewClient returns a new Client interface for the given endpoint

func (*Client) Call

func (c *Client) Call(path string, values url.Values) (string, error)

Call performs a remote action and returns the result

func (*Client) RemoteVersion

func (c *Client) RemoteVersion() string

RemoteVersion returns the version of the remotely connected Log Courier

func (*Client) Request

func (c *Client) Request(path string) (string, error)

Request performs a request and returns a pretty response It will defer to Call method if the path is a known Call path

type Config

type Config struct {
	Enabled bool   `config:"enabled"`
	Bind    string `config:"listen address"`
	// contains filtered or unexported fields
}

Config holds the admin configuration It also holds the root of the API which pipeline segments can attach to in order to provide action functions and status returns

func (*Config) InitDefaults

func (c *Config) InitDefaults()

InitDefaults initialises default values

func (*Config) SetEntry

func (c *Config) SetEntry(path string, entry APINavigatable)

SetEntry sets a new root API entry

func (*Config) Validate

func (c *Config) Validate() (err error)

Validate validates the config structure

type ErrUnknown

type ErrUnknown error

ErrUnknown represents a successful request where Log Courier returned an error, as opposed to an error processing a request

type ErrorResponse

type ErrorResponse struct {
	Message string
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type PongResponse

type PongResponse struct {
}

type ReloadResponse

type ReloadResponse struct {
}

type Response

type Response struct {
	Response interface{}
}

type Server

type Server struct {
	core.PipelineSegment
	core.PipelineConfigReceiver
	// contains filtered or unexported fields
}

Server provides a REST interface for administration

func NewServer

func NewServer(pipeline *core.Pipeline, config *config.Config, reloadFunc func() error) (*Server, error)

NewServer creates a new admin listener on the pipeline

func (*Server) Run

func (l *Server) Run()

Run is the main routine for the admin listener

type V1Client

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

V1Client is a client compatible with Log Courier 1.x

func NewV1Client

func NewV1Client(adminConnect string) (*V1Client, error)

NewV1Client returns a new admin client compatible with Log Courier 1.x

func (*V1Client) FetchSnapshot

func (c *V1Client) FetchSnapshot() (*core.Snapshot, error)

FetchSnapshot requests a status snapshot from Log Courier

func (*V1Client) Ping

func (c *V1Client) Ping() error

Ping sends a PING command to test the admin connection

func (*V1Client) Reload

func (c *V1Client) Reload() error

Reload requests the connected Log Courier to reload its configuration

Jump to

Keyboard shortcuts

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