func (conn *HTTPSEapiConnection) enableCertificateVerification() {
	conn.enforceVerification = true
}
enableCertificateVerification enables https verification
package goeapi
import (
	"bytes"
	"crypto/tls"
	"encoding/json"
	"fmt"
	"net"
	"net/http"
	"net/url"
	"os"
	"strconv"
	"strings"
	"time"
)
type EapiConnectionEntity interface {
	Execute(commands []interface{}, encoding string) (*JSONRPCResponse, error)
	SetTimeout(to uint32)
	SetDisableKeepAlive(disableKeepAlive bool)
	Error() error
}
type EapiConnection struct {
	transport        string
	err              error
	url              string
	host             string
	port             int
	path             string
	auth             *url.Userinfo
	timeOut          uint32
	disableKeepAlive bool
}
func (conn *EapiConnection) Execute(commands []interface{},
	encoding string) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No connection")
	}
	return &JSONRPCResponse{}, fmt.Errorf("Not Currently Implemented")
}
func (conn *EapiConnection) Authentication(username string, passwd string) {
	username = strings.Replace(username, "\n", "", -1)
	passwd = strings.Replace(passwd, "\n", "", -1)
	conn.auth = url.UserPassword(username, passwd)
}
func (conn *EapiConnection) getURL() string {
	if conn == nil {
		return ""
	}
	url := url.URL{
		Scheme: conn.transport,
		User:   conn.auth,
		Host:   conn.host + ":" + strconv.Itoa(conn.port),
		Path:   "/command-api",
	}
	return url.String()
}
func (conn *EapiConnection) Error() error {
	if conn == nil {
		return nil
	}
	return conn.err
}
func (conn *EapiConnection) SetError(e error) {
	if conn == nil {
		return
	}
	conn.err = e
}
func (conn *EapiConnection) ClearError() {
	if conn == nil {
		return
	}
	conn.err = nil
}
func (conn *EapiConnection) SetTimeout(timeOut uint32) {
	var val uint32
	if conn == nil {
		return
	}
	if timeOut > 65535 {
		val = 60
	} else {
		val = timeOut
	}
	conn.timeOut = val
}
func (conn *EapiConnection) SetDisableKeepAlive(disableKeepAlive bool) {
	conn.disableKeepAlive = disableKeepAlive
}
func buildJSONRequest(commands []interface{},
	encoding string, reqid string) ([]byte, error) {
	p := Parameters{1, commands, encoding}
	req := Request{"2.0", "runCmds", p, reqid}
	data, err := json.Marshal(req)
	return data, err
}
type SocketEapiConnection struct {
	EapiConnection
}
const defaultUnixSocket = "/var/run/command-api.sock"
func NewSocketEapiConnection(transport string, host string, username string,
	password string, port int) EapiConnectionEntity {
	conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60}
	return &SocketEapiConnection{conn}
}
func (conn *SocketEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No Connection")
	}
	timeOut := time.Duration(time.Duration(conn.timeOut) * time.Second)
	fakeURL := "http://localhost/command-api"
	var fakeDial = func(proto, addr string) (conn net.Conn, err error) {
		return net.Dial("unix", defaultUnixSocket)
	}
	client := &http.Client{
		Timeout: timeOut,
		Transport: &http.Transport{
			Dial: fakeDial,
		},
	}
	resp, err := client.Post(fakeURL, "application/json", bytes.NewReader(data))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	defer func() {
		if cerr := resp.Body.Close(); cerr != nil {
			err = cerr
			conn.SetError(err)
		}
	}()
	jsonRsp, err := decodeEapiResponse(resp)
	if err != nil {
		conn.SetError(err)
		return jsonRsp, err
	}
	return jsonRsp, nil
}
func (conn *SocketEapiConnection) Execute(commands []interface{},
	encoding string) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No connection")
	}
	conn.ClearError()
	data, err := buildJSONRequest(commands, encoding, strconv.Itoa(os.Getpid()))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	return conn.send(data)
}
type HTTPLocalEapiConnection struct {
	EapiConnection
}
const UseDefaultPortNum = -1
const DefaultHTTPLocalPort = 8080
func NewHTTPLocalEapiConnection(transport string, host string, username string,
	password string, port int) EapiConnectionEntity {
	if port == UseDefaultPortNum {
		port = DefaultHTTPLocalPort
	}
	conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60}
	return &HTTPLocalEapiConnection{conn}
}
func (conn *HTTPLocalEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No Connection")
	}
	return &JSONRPCResponse{}, fmt.Errorf("Not Currently Implemented")
}
func (conn *HTTPLocalEapiConnection) Execute(commands []interface{},
	encoding string) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No connection")
	}
	conn.ClearError()
	data, err := buildJSONRequest(commands, encoding, strconv.Itoa(os.Getpid()))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	return conn.send(data)
}
type HTTPEapiConnection struct {
	EapiConnection
}
const DefaultHTTPPort = 80
func NewHTTPEapiConnection(transport string, host string, username string,
	password string, port int) EapiConnectionEntity {
	if port == UseDefaultPortNum {
		port = DefaultHTTPPort
	}
	conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60, disableKeepAlive: false}
	conn.Authentication(username, password)
	return &HTTPEapiConnection{conn}
}
func (conn *HTTPEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No Connection")
	}
	tr := &http.Transport{
		DisableKeepAlives: conn.disableKeepAlive,
	}
	timeOut := time.Duration(time.Duration(conn.timeOut) * time.Second)
	client := &http.Client{
		Timeout:   timeOut,
		Transport: tr,
	}
	url := conn.getURL()
	resp, err := client.Post(url, "application/json", bytes.NewReader(data))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	defer func() {
		if cerr := resp.Body.Close(); cerr != nil {
			err = cerr
			conn.SetError(err)
		}
	}()
	jsonRsp, err := decodeEapiResponse(resp)
	if err != nil {
		conn.SetError(err)
		return jsonRsp, err
	}
	return jsonRsp, nil
}
func (conn *HTTPEapiConnection) Execute(commands []interface{},
	encoding string) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No connection")
	}
	conn.ClearError()
	data, err := buildJSONRequest(commands, encoding, strconv.Itoa(os.Getpid()))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	return conn.send(data)
}
type HTTPSEapiConnection struct {
	EapiConnection
	path                string
	enforceVerification bool
}
const DefaultHTTPSPort = 443
const DefaultHTTPSPath = "/command-api"
func NewHTTPSEapiConnection(transport string, host string, username string,
	password string, port int) EapiConnectionEntity {
	if port == UseDefaultPortNum {
		port = DefaultHTTPSPort
	}
	path := DefaultHTTPSPath
	conn := EapiConnection{transport: transport, host: host, port: port, timeOut: 60, disableKeepAlive: false}
	conn.Authentication(username, password)
	return &HTTPSEapiConnection{path: path, EapiConnection: conn}
}
func (conn *HTTPSEapiConnection) send(data []byte) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No Connection")
	}
	timeOut := time.Duration(time.Duration(conn.timeOut) * time.Second)
	url := conn.getURL()
	tr := &http.Transport{
		TLSClientConfig:   &tls.Config{InsecureSkipVerify: true},
		DisableKeepAlives: conn.disableKeepAlive,
	}
	client := &http.Client{
		Timeout:   timeOut,
		Transport: tr,
	}
	resp, err := client.Post(url, "application/json", bytes.NewReader(data))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	defer func() {
		if cerr := resp.Body.Close(); cerr != nil {
			err = cerr
			conn.SetError(err)
		}
	}()
	jsonRsp, err := decodeEapiResponse(resp)
	if err != nil {
		conn.SetError(err)
		return jsonRsp, err
	}
	return jsonRsp, nil
}
func (conn *HTTPSEapiConnection) Execute(commands []interface{},
	encoding string) (*JSONRPCResponse, error) {
	if conn == nil {
		return &JSONRPCResponse{}, fmt.Errorf("No connection")
	}
	conn.ClearError()
	data, err := buildJSONRequest(commands, encoding, strconv.Itoa(os.Getpid()))
	if err != nil {
		conn.SetError(err)
		return &JSONRPCResponse{}, err
	}
	return conn.send(data)
}
func (conn *HTTPSEapiConnection) disableCertificateVerification() {
	conn.enforceVerification = false
}