Documentation
¶
Index ¶
- func CreateAddresses(protocol, startIp string, port, number int) []string
- func ExpandAddresses(protocol string, addresses ...string) []string
- type Connector
- type Phone
- func (p *Phone) Backup() ([]byte, error)
- func (p *Phone) DownloadParameters() (*params.Parameters, error)
- func (p *Phone) DownloadPhoneBook() (*string, error)
- func (p *Phone) Logout() error
- func (p *Phone) Reset() error
- func (p *Phone) Restore(data []byte) error
- func (p *Phone) UploadParameters(params params.Parameters) error
- func (p *Phone) UploadPhoneBook(payload string) error
- type PhoneAction
- type PhoneResult
- type ResultCallback
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAddresses ¶
Creates number addresses to connect to phones. This first Address is given by startIp, which is always inclusive. If the startIp is not a valid IP, then an empty slice is returned. The resulting slice can be used in the MultipleConnect function of the Connector.
Attention: This method does not contain any IP sub net logic, it just increments the ip addresses "stupidly": IP addresses like 10.20.30.255 or 10.20.255.0 may occur, and depending on the subnet these are valid host IP addresses or not. The method never returns syntactically wrong IP addresses.
Example ¶
addresses := CreateAddresses("http", "10.1.254.254", 8081, 3)
fmt.Printf("Length of addresses is %d.\n", len(addresses))
fmt.Printf("%s\n", addresses[0])
fmt.Printf("%s\n", addresses[1])
fmt.Printf("%s\n", addresses[2])
Output: Length of addresses is 3. http://10.1.254.254:8081 http://10.1.254.255:8081 http://10.1.255.0:8081
func ExpandAddresses ¶
Expands IP Addresses. If an passed Address cannot be parsed, then it is returned as is.
Example ¶
addresses := ExpandAddresses("http", "127.0.0.1", "not an ip", "10.20.30.40+2", "20.20.20.20:8080+1", "30.30.30.30:1234")
for _, address := range addresses {
fmt.Printf("%s\n", address)
}
Output: http://127.0.0.1:80 not an ip http://10.20.30.40:80 http://10.20.30.41:80 http://10.20.30.42:80 http://20.20.20.20:8080 http://20.20.20.21:8080 http://30.30.30.30:1234
Types ¶
type Connector ¶
A connector is used to obtain a login token from a telephone and perform REST actions on the telephone. The connector can be used to either connect to only one telephone or to a bunch of telephones at the same time.
func (*Connector) Run ¶
func (c *Connector) Run(loginCallback ResultCallback, operation PhoneAction, logoutCallback ResultCallback)
type Phone ¶
type Phone struct {
Address string
// contains filtered or unexported fields
}
A phone represents a http Client that talks to exactly on physical telephone. A phone needs to be created with a Connector (see example). It is strongly recommended to defer calling the method Phone#Logout() because most IP620/630 only allow one active token at a time.
Example ¶
connector := Connector{Client: http.DefaultClient, UserName: username, Password: password}
phone, _ := connector.SingleConnect("http://example.com:8080")
book, _ := phone.DownloadPhoneBook()
fmt.Print(book)
func (*Phone) DownloadParameters ¶
func (p *Phone) DownloadParameters() (*params.Parameters, error)
Downloads the phone's parameters, for example the function key definitions from the telephone or returns an error if the download is not successful.
func (*Phone) DownloadPhoneBook ¶
Downloads the phone book from the telephone. In case of an error the returned string is nil.
func (*Phone) Logout ¶
Sends a logout request to the phone. If the request passes without error then the token of the phone is reset. Further usage of the phone struct will most likely not work. If and error is returned, then the token stored in this telephone may or may not be used again, depending on the error.
func (*Phone) UploadParameters ¶
func (p *Phone) UploadParameters(params params.Parameters) error
Uploads the parameters to the telephone. Returns an error if an error occurred during the request or if the response code was not successful.
func (*Phone) UploadPhoneBook ¶
Uploads the payload as phone book to the telephone. Note, that the IP620/630 treat local phone books in XML format. However, this method does not check the XML format of the payload, it rather uploads it and leaves the parsing to the telephone. If an error occurs, or the response does not carry a successful status, an non-nil error is returned.
type PhoneAction ¶
type PhoneAction func(p *Phone)
type PhoneResult ¶
type ResultCallback ¶
type ResultCallback func(p *PhoneResult)