edgeos
–
import “astuart.co/edgeos-rest/pkg/edgeos”
Package edgeos provides a Go client for interfacing with EdgeOS devices. It has
been developed and tested against the ERLite running v1.9.1 firmware. Thus far,
it serves primarily to expose high-level generic functionality as well as a
specific implementation for the port forwarding features.
Usage
type Client
type Client struct {
Username, Password, Address string
Path, Suffix, LoginEndpoint string
}
A Client can interact with the EdgeOS REST API
func NewClient
func NewClient(addr, username, password string) (*Client, error)
NewClient returns an initialized Client for interacting with an EdgeOS device
func (*Client) Feature
func (c *Client) Feature(s Scenario) (Resp, error)
Feature takes an EdgeOS “Scenario” as an argument and returns a Resp
representing the JSON returned by the API.
func (*Client) FeatureFor
func (c *Client) FeatureFor(s Scenario, out interface{}) error
FeatureFor takes a scenario and a pointer to a struct. The JSON response will be
deserialized into the out object, and any errors will be returned.
func (*Client) Get
func (c *Client) Get() (Resp, error)
Get returns some standard configuration information from EdgeOS
func (*Client) GetJSON
func (c *Client) GetJSON(endpoint string, data interface{}) (Resp, error)
GetJSON takes an endpoint and data for the POST body (or GET if data is nil)
and returns the Resp type that contains the data response from the endpoint.
func (*Client) JSONFor
func (c *Client) JSONFor(endpoint string, data, out interface{}) error
JSONFor is a high-level method that takes an endpoint, a post body, and a
pointer to a struct into which the JSON should be decoded.
func (*Client) Login
func (c *Client) Login() error
Login sets up an http session with the EdgeOS device using the supplied endpoint
and credentials
func (*Client) PortForwards
func (c *Client) PortForwards() (*FeatureResponse, error)
func (*Client) SetFeature
func (c *Client) SetFeature(s Scenario, data interface{}) (Resp, error)
SetFeature allows users to programmatically update features
func (*Client) SetFeatureFor
func (c *Client) SetFeatureFor(s Scenario, data interface{}, out interface{}) error
SetFeatureFor takes a “Scenario”, some data to send, and a pointer to an
interface into which the JSON response will be decoded.
type Config
type Config struct {
Success bool `json:"success"`
GET struct {
Firewall struct {
AllPing string `json:"all-ping"`
BroadcastPing string `json:"broadcast-ping"`
Ipv6ReceiveRedirects string `json:"ipv6-receive-redirects"`
Ipv6SrcRoute string `json:"ipv6-src-route"`
IPSrcRoute string `json:"ip-src-route"`
LogMartians string `json:"log-martians"`
Name struct {
LANLOCAL struct {
DefaultAction string `json:"default-action"`
Description string `json:"description"`
Rule struct {
Num1 struct {
Action string `json:"action"`
Description string `json:"description"`
Destination struct {
Group struct {
AddressGroup string `json:"address-group"`
} `json:"group"`
} `json:"destination"`
Log string `json:"log"`
Protocol string `json:"protocol"`
Source struct {
Group interface{} `json:"group"`
} `json:"source"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"1"`
Num2 struct {
Action string `json:"action"`
Description string `json:"description"`
Destination struct {
Group struct {
AddressGroup string `json:"address-group"`
} `json:"group"`
} `json:"destination"`
Log string `json:"log"`
Protocol string `json:"protocol"`
Source struct {
Group interface{} `json:"group"`
} `json:"source"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"2"`
} `json:"rule"`
} `json:"LAN_LOCAL"`
WANIN struct {
DefaultAction string `json:"default-action"`
Description string `json:"description"`
EnableDefaultLog interface{} `json:"enable-default-log"`
Rule struct {
Num20 struct {
Action string `json:"action"`
Description string `json:"description"`
Log string `json:"log"`
Protocol string `json:"protocol"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"20"`
Num30 struct {
Action string `json:"action"`
Description string `json:"description"`
Log string `json:"log"`
Protocol string `json:"protocol"`
Source struct {
Group interface{} `json:"group"`
} `json:"source"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"30"`
} `json:"rule"`
} `json:"WAN_IN"`
WANLOCAL struct {
DefaultAction string `json:"default-action"`
Description string `json:"description"`
EnableDefaultLog interface{} `json:"enable-default-log"`
Rule struct {
Num10 struct {
Action string `json:"action"`
Description string `json:"description"`
Log string `json:"log"`
Protocol string `json:"protocol"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"10"`
Num20 struct {
Action string `json:"action"`
Description string `json:"description"`
Destination struct {
Group struct {
AddressGroup string `json:"address-group"`
} `json:"group"`
} `json:"destination"`
Log string `json:"log"`
Protocol string `json:"protocol"`
} `json:"20"`
Num30 struct {
Action string `json:"action"`
Description string `json:"description"`
Log string `json:"log"`
Protocol string `json:"protocol"`
Source struct {
Group interface{} `json:"group"`
} `json:"source"`
State struct {
Established string `json:"established"`
Invalid string `json:"invalid"`
New string `json:"new"`
Related string `json:"related"`
} `json:"state"`
} `json:"30"`
} `json:"rule"`
} `json:"WAN_LOCAL"`
} `json:"name"`
Options interface{} `json:"options"`
ReceiveRedirects string `json:"receive-redirects"`
SendRedirects string
提示:代码过长已自动截断
type Feature
type Feature struct {
Data PortForwards
// Data interface{}
Definition interface{}
Deletable string
Success string
}
type FeatureResponse
type FeatureResponse struct {
Response
Feature Feature `json:"FEATURE"`
}
FeatureResponse encapsulates the Response metadata and the Feature
type LanConfig
type LanConfig map[string]string
LanConfig is a simple string map that encapsulates the LAN configuration data.
type PortForward
type PortForward struct {
PortFrom string `json:"original-port"`
PortTo string `json:"forward-to-port"`
IPTo string `json:"forward-to-address"`
Protocol string `json:"protocol"`
Description string `json:"description"`
}
PortForward is a struct that represents a port forwarding rule
type PortForwards
type PortForwards struct {
AutoFirewall string `json:"auto-firewall"`
HairpinNAT string `json:"hairpin-nat"`
WAN string `json:"wan"`
Lans []LanConfig `json:"lans-config"`
Rules []PortForward `json:"rules-config"`
}
PortForwards is a struct that represents the response from the API for with the
list of port forwards, etc.
type Resp
type Resp map[string]interface{}
Resp is the basic response type for the EdgeOS API. Higher-level methods will
tend to skip this type and return strongly-typed objects for specific endpoints.
type Response
type Response struct {
Success bool `json:"success"`
Error string `json:"error"`
}
Response is a struct (intended for embedding) that represents response metadata
returned by the EdgeOS API.
type Scenario
type Scenario string
Scenario is just a string type to encourage the use of internal constants.
const (
PortForwarding Scenario = ".Port_Forwarding"
)
Common feature endpoints
评论