api

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: GPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DtLayout            = "2006-01-02 15:04:05"
	DtLayoutZeroSeconds = "2006-01-02 15:04:00"
	DtLayoutSecond      = "20060102150405"
	DtLayoutMinute      = "200601021504"
	DtLayoutHour        = "2006010215"
	DtLayoutDay         = "20060102"
	DtLayoutMonth       = "200601"
	DtLayoutYear        = "2006"
)
View Source
const (
	PointTypeInstant = "instant"
	PointTypeBoot    = "boot"
	PointTypeDaily   = "daily"
	PointTypeMonthly = "monthly"
	PointTypeYearly  = "yearly"
	PointTypeTotal   = "total"
)
View Source
const NullEndPoint = "nullEndPoint"
View Source
const (
	VirtualPsId = "virtual"
)

Variables

View Source
var Points = PointsMap{}/* 104 elements not displayed */

Points Discovered points from the API

Functions

func AppendUrl

func AppendUrl(host string, endpoint string) *url.URL

func CheckString

func CheckString(name string, rc string) error

CheckString RequestCommon checks

func CleanString

func CleanString(s string) string

func DivideByThousand

func DivideByThousand(num string) (string, error)

func DivideByThousandIfRequired

func DivideByThousandIfRequired(value string, unit string) (string, string)

DivideByThousandIfRequired Sigh.... Another dodgy one.

func Float32ToString

func Float32ToString(num float64) string

func Float64ToString

func Float64ToString(num float64) string

func GetPercent

func GetPercent(value float64, max float64) float64

func GetUrl

func GetUrl(u string) *url.URL

func HelpDataType

func HelpDataType() string

func IsActive

func IsActive(value float64) bool

func JoinDevicePoint

func JoinDevicePoint(device string, point string) string

func MarshalJSON

func MarshalJSON(endpoint EndPoint) ([]byte, error)

func NameDevicePoint

func NameDevicePoint(device string, point string) string

func NameDevicePointInt

func NameDevicePointInt(device string, point int64) string

func PointToName

func PointToName(s string) string

func SetPoint

func SetPoint(point string) string

func TimeNowString

func TimeNowString() string

Types

type Api

type Api struct{}

type Area

type Area interface {
	Init(*Web) AreaStruct
	GetAreaName() AreaName
	GetEndPoints() TypeEndPoints
	Call(name EndPointName) output.Json
	SetRequest(name EndPointName, ref interface{}) error
	GetRequest(name EndPointName) output.Json
	GetResponse(name EndPointName) output.Json
	GetData(name EndPointName) output.Json
	IsValid(name EndPointName) error
	GetError(name EndPointName) error
}

type AreaName

type AreaName string

func GetArea

func GetArea(v interface{}) AreaName

type AreaNames

type AreaNames []AreaName

type AreaStruct

type AreaStruct struct {
	ApiRoot   interface{} // *web.Web
	Name      AreaName
	EndPoints TypeEndPoints
	Error     error
}

func (AreaStruct) CountDisabled

func (as AreaStruct) CountDisabled() int

func (AreaStruct) CountEnabled

func (as AreaStruct) CountEnabled() int

func (AreaStruct) Exists

func (as AreaStruct) Exists(name EndPointName) error

func (*AreaStruct) GetEndPoint

func (as *AreaStruct) GetEndPoint(name EndPointName) EndPoint

func (AreaStruct) ListEndpoints

func (as AreaStruct) ListEndpoints()

func (*AreaStruct) SortEndPoints

func (as *AreaStruct) SortEndPoints() []EndPointName

type Areas

type Areas map[AreaName]AreaStruct // TypeEndPoints		// Map of EndPoints by area name.

func (*Areas) EndpointExists

func (an *Areas) EndpointExists(area AreaName, name EndPointName) error

func (*Areas) Exists

func (an *Areas) Exists(area string) bool

func (*Areas) GetArea

func (an *Areas) GetArea(area AreaName) *Area

func (*Areas) GetEndPoint

func (an *Areas) GetEndPoint(area AreaName, name EndPointName) EndPoint

func (*Areas) GetRequest

func (an *Areas) GetRequest(area AreaName, endpoint EndPointName) output.Json

func (*Areas) GetResponse

func (an *Areas) GetResponse(area AreaName, endpoint EndPointName) output.Json

func (Areas) ListAreas

func (an Areas) ListAreas()

func (Areas) ListEndpoints

func (an Areas) ListEndpoints(area string) error

func (*Areas) NotExists

func (an *Areas) NotExists(area string) bool

func (*Areas) SetRequest

func (an *Areas) SetRequest(area AreaName, name EndPointName, ref interface{}) error

func (*Areas) SortAreas

func (an *Areas) SortAreas() AreaNames

type DataEntry

type DataEntry struct {
	EndPoint string   `json:"endpoint"`
	Point    *Point   `json:"point"`
	Date     DateTime `json:"date"`
	// Id        string `json:"id"`
	// GroupName string `json:"group_name"`
	// Name      string `json:"name"`
	// Unit       string   `json:"unit"`
	Value      string  `json:"value"`
	ValueFloat float64 `json:"value_float"`
	Index      int     `json:"index"`
}

func CreateDataEntryActive

func CreateDataEntryActive(date DateTime, psId string, point string, name string, value float64) DataEntry

func CreateDataEntryString

func CreateDataEntryString(date DateTime, psId string, point string, name string, value string) DataEntry

func CreateDataEntryUnitValue

func CreateDataEntryUnitValue(date DateTime, psId string, point string, name string, value UnitValue) DataEntry

func (*DataEntry) CreateAlias

func (de *DataEntry) CreateAlias(psId string, point string, name string) DataEntry

func (*DataEntry) CreateFloat

func (de *DataEntry) CreateFloat(psId string, point string, name string, value float64) DataEntry

func (*DataEntry) CreateState

func (de *DataEntry) CreateState(psId string, point string, name string) DataEntry

func (*DataEntry) UpdateMeta

func (de *DataEntry) UpdateMeta(date *DateTime, psId string, point string, name string)

type DataMap

type DataMap struct {
	Entries map[string]DataEntry
	Order   []string
}

func NewDataMap

func NewDataMap() DataMap

func (*DataMap) Add

func (dm *DataMap) Add(point string, de DataEntry)

func (*DataMap) AddEntry

func (dm *DataMap) AddEntry(point Point, date DateTime, value string)

func (*DataMap) AddEntryFromRef

func (dm *DataMap) AddEntryFromRef(refPoint Point, point Point, date DateTime, value string)

func (*DataMap) AddFloat

func (dm *DataMap) AddFloat(psId string, point string, name string, date DateTime, value float64)

func (*DataMap) AddInt

func (dm *DataMap) AddInt(psId string, point string, name string, date DateTime, value int64)

func (*DataMap) AddString

func (dm *DataMap) AddString(psId string, point string, name string, date DateTime, value string)

func (*DataMap) AddUnitValue

func (dm *DataMap) AddUnitValue(endpoint string, psId string, point string, name string, date DateTime, ref UnitValue)

func (*DataMap) CopyEntry

func (dm *DataMap) CopyEntry(entry string) *DataEntry

func (*DataMap) CopyPoint

func (dm *DataMap) CopyPoint(refname string, psId string, point string, name string, value float64)

func (*DataMap) FromRefAddAlias

func (dm *DataMap) FromRefAddAlias(refname string, psId string, point string, name string)

func (*DataMap) FromRefAddAlias2

func (dm *DataMap) FromRefAddAlias2(refname string, psId string, point string, name string)

func (*DataMap) FromRefAddFloat

func (dm *DataMap) FromRefAddFloat(refname string, psId string, point string, name string, value float64)

func (*DataMap) FromRefAddState

func (dm *DataMap) FromRefAddState(refname string, psId string, point string, name string)

func (*DataMap) GetEntry

func (dm *DataMap) GetEntry(entry string) DataEntry

func (*DataMap) GetFloatValue

func (dm *DataMap) GetFloatValue(entry string) float64

func (*DataMap) GetPercent

func (dm *DataMap) GetPercent(value string, max string) float64

func (*DataMap) GetValue

func (dm *DataMap) GetValue(refname string) float64

func (*DataMap) LowerUpper

func (dm *DataMap) LowerUpper(lower string, upper string) float64

func (*DataMap) StructToPoints

func (dm *DataMap) StructToPoints(endpoint string, ref interface{})

type DateTime

type DateTime struct {
	time.Time
	DateType string
	Error    error
	// contains filtered or unexported fields
}

func NewDateTime

func NewDateTime(date string) DateTime

func (*DateTime) GetDayEndTimestamp

func (dt *DateTime) GetDayEndTimestamp() string

func (*DateTime) GetDayStartTimestamp

func (dt *DateTime) GetDayStartTimestamp() string

func (DateTime) PrintFull

func (dt DateTime) PrintFull() string

func (DateTime) String

func (dt DateTime) String() string

type EndPoint

type EndPoint interface {
	GetArea() AreaName
	GetName() EndPointName
	GetUrl() EndPointUrl
	IsDisabled() bool
	Help() string

	Call() EndPoint
	SetError(string, ...interface{}) EndPoint
	GetError() error
	IsError() bool
	MarshalJSON() ([]byte, error)
	ReadDataFile() error
	WriteDataFile() error
	String() string
	GetJsonData(bool) output.Json

	SetRequest(ref interface{}) EndPoint // EndPointStruct
	SetRequestByJson(j output.Json) EndPoint
	RequestRef() interface{}
	GetRequestJson() output.Json
	IsRequestValid() error
	RequestString() string
	RequestFingerprint() string

	SetResponse([]byte) EndPoint // EndPointStruct
	ResponseRef() interface{}
	GetResponseJson() output.Json
	IsResponseValid() error
	ResponseString() string

	// WriteCache() error
	// ReadCache() EndPoint
	// CheckCache() bool
	CacheFilename() string
	SetCacheTimeout(duration time.Duration) EndPoint
	GetCacheTimeout() time.Duration
}

type EndPointName

type EndPointName string

func GetName

func GetName(v interface{}) EndPointName

type EndPointStruct

type EndPointStruct struct {
	ApiRoot     Web `json:"-"`
	RawResponse []byte

	Area           AreaName     `json:"area"`
	Name           EndPointName `json:"name"`
	Url            EndPointUrl  `json:"url"`
	FileNamePrefix string
	Request        interface{} `json:"-"`
	Response       interface{} `json:"-"`
	Error          error       `json:"-"`
}

func (*EndPointStruct) ApiCacheFilename

func (ep *EndPointStruct) ApiCacheFilename(request interface{}) string

func (*EndPointStruct) ApiFingerprint

func (ep *EndPointStruct) ApiFingerprint(request interface{}) string

func (*EndPointStruct) ApiReadDataFile

func (ep *EndPointStruct) ApiReadDataFile(ref interface{}) error

FileRead Retrieves data from a local file.

func (*EndPointStruct) ApiWriteDataFile

func (ep *EndPointStruct) ApiWriteDataFile(ref interface{}) error

FileWrite Saves data to a file path.

func (*EndPointStruct) Call

func (ep *EndPointStruct) Call() output.Json

func (*EndPointStruct) FileExists

func (ep *EndPointStruct) FileExists(fn string) bool

FileExists Checks for existance of a local file.

func (*EndPointStruct) GetArea

func (ep *EndPointStruct) GetArea() AreaName

func (*EndPointStruct) GetCsvFilename

func (ep *EndPointStruct) GetCsvFilename() string

func (*EndPointStruct) GetFilePath

func (ep *EndPointStruct) GetFilePath() string

func (*EndPointStruct) GetImageFilename

func (ep *EndPointStruct) GetImageFilename() string

func (*EndPointStruct) GetJsonFilename

func (ep *EndPointStruct) GetJsonFilename() string

func (*EndPointStruct) GetName

func (ep *EndPointStruct) GetName() EndPointName

func (*EndPointStruct) GetRequest

func (ep *EndPointStruct) GetRequest() output.Json

func (*EndPointStruct) GetResponse

func (ep *EndPointStruct) GetResponse() output.Json

func (*EndPointStruct) GetUrl

func (ep *EndPointStruct) GetUrl() EndPointUrl

func (*EndPointStruct) IsValid

func (ep *EndPointStruct) IsValid() error

func (EndPointStruct) ResponseAsJson

func (ep EndPointStruct) ResponseAsJson(raw bool, r interface{}) output.Json

func (*EndPointStruct) SetFilenamePrefix

func (ep *EndPointStruct) SetFilenamePrefix(format string, args ...interface{}) string

func (*EndPointStruct) SetRequest

func (ep *EndPointStruct) SetRequest(ref interface{}) error

func (EndPointStruct) String

func (ep EndPointStruct) String() string

type EndPointUrl

type EndPointUrl struct {
	EndPoint *url.URL `json:"endpoint"`
	Error    error    `json:"error"`
}

func SetUrl

func SetUrl(endpoint string) EndPointUrl

func (EndPointUrl) AppendPath

func (u EndPointUrl) AppendPath(endpoint string) EndPointUrl

func (*EndPointUrl) IsValid

func (u *EndPointUrl) IsValid() error

func (*EndPointUrl) MarshalJSON

func (u *EndPointUrl) MarshalJSON() ([]byte, error)

func (EndPointUrl) String

func (u EndPointUrl) String() string

func (*EndPointUrl) UnmarshalJSON

func (u *EndPointUrl) UnmarshalJSON(data []byte) error

type Point

type Point struct {
	EndPoint  string `json:"endpoint"`
	FullId    string `json:"full_id"`
	PsKey     string `json:"ps_key"`
	Id        string `json:"id"`
	GroupName string `json:"group_name"`
	Name      string `json:"name"`
	Unit      string `json:"unit"`
	Type      string `json:"type"`
	Valid     bool   `json:"valid"`
}

func CreatePoint

func CreatePoint(psId string, point string, name string, unit string) *Point

func GetDevicePoint

func GetDevicePoint(devicePoint string) *Point

func GetPoint

func GetPoint(device string, point string) *Point

func GetPointInt

func GetPointInt(device string, point int64) *Point

func ResolvePoint

func ResolvePoint(point string) *Point

func (Point) IsDaily

func (p Point) IsDaily() bool

func (Point) IsInstant

func (p Point) IsInstant() bool

func (Point) IsMonthly

func (p Point) IsMonthly() bool

func (Point) IsTotal

func (p Point) IsTotal() bool

func (Point) IsYearly

func (p Point) IsYearly() bool

func (Point) String

func (p Point) String() string

func (*Point) WhenReset

func (p *Point) WhenReset() string

type PointsMap

type PointsMap map[string]Point

func (PointsMap) Get

func (pm PointsMap) Get(device string, point string) *Point

func (PointsMap) GetDevicePoint

func (pm PointsMap) GetDevicePoint(devicePoint string) *Point

func (*PointsMap) Resolve

func (pm *PointsMap) Resolve(point string) *Point

type Request

type Request struct {
	RequestCommon
}

type RequestCommon

type RequestCommon struct {
	Appkey    string `json:"appkey" required:"true"`
	Lang      string `json:"lang"`
	SysCode   string `json:"sys_code" required:"true"`
	Token     string `json:"token"`
	UserID    string `json:"user_id"`
	ValidFlag string `json:"valid_flag"`
}

func (RequestCommon) IsValid

func (req RequestCommon) IsValid() error

func (RequestCommon) String

func (req RequestCommon) String() string

type Response

type Response struct {
	ResponseCommon
}

type ResponseCommon

type ResponseCommon struct {
	ReqSerialNum string        `json:"req_serial_num"`
	ResultCode   string        `json:"result_code"`
	ResultData   []interface{} `json:"result_data"`
	ResultMsg    string        `json:"result_msg"`
}

func (ResponseCommon) CheckResultCode

func (req ResponseCommon) CheckResultCode() error

func (ResponseCommon) CheckResultMessage

func (req ResponseCommon) CheckResultMessage() error

func (ResponseCommon) IsTokenInvalid

func (req ResponseCommon) IsTokenInvalid() bool

func (ResponseCommon) IsTokenValid

func (req ResponseCommon) IsTokenValid() bool

func (ResponseCommon) IsValid

func (req ResponseCommon) IsValid() error

func (ResponseCommon) String

func (req ResponseCommon) String() string

type TemplatePoint

type TemplatePoint struct {
	Description string
	PsKey       string
	PointId     string
	Unit        string
}

type TemplatePoints

type TemplatePoints []TemplatePoint

func CreatePoints

func CreatePoints(points []string) TemplatePoints

func (*TemplatePoints) GetPoint

func (t *TemplatePoints) GetPoint(pskey string, point string) TemplatePoint

func (*TemplatePoints) PrintKeys

func (t *TemplatePoints) PrintKeys() string

func (*TemplatePoints) PrintPoints

func (t *TemplatePoints) PrintPoints() string

type TypeEndPoints

type TypeEndPoints map[EndPointName]EndPoint // Map of EndPoints by endpoint name.

func (TypeEndPoints) Exists

func (ps TypeEndPoints) Exists(name EndPointName) error

func (*TypeEndPoints) GetDisabled

func (ps *TypeEndPoints) GetDisabled() TypeEndPoints

func (*TypeEndPoints) GetEnabled

func (ps *TypeEndPoints) GetEnabled() TypeEndPoints

func (*TypeEndPoints) GetEndPoint

func (ps *TypeEndPoints) GetEndPoint(name EndPointName) EndPoint

func (*TypeEndPoints) SortEndPoints

func (ps *TypeEndPoints) SortEndPoints() []EndPointName

func (TypeEndPoints) String

func (ps TypeEndPoints) String() string

type UnitValue

type UnitValue struct {
	Unit       string  `json:"unit"`
	Value      string  `json:"value"`
	ValueFloat float64 `json:"value_float,omitempty"`
	ValueInt   int64   `json:"value_int,omitempty"`
}

func CreateUnitValue

func CreateUnitValue(value string, unit string) UnitValue

func JsonToUnitValue

func JsonToUnitValue(j string) UnitValue

func (*UnitValue) UnitValueFix

func (ref *UnitValue) UnitValueFix() UnitValue

func (*UnitValue) UnitValueToPoint

func (ref *UnitValue) UnitValueToPoint(psId string, point string, name string) *Point

type UnitValueMap

type UnitValueMap map[string]UnitValue

func GetStructKeys

func GetStructKeys(ref interface{}, keys ...string) UnitValueMap

func (*UnitValueMap) Sort

func (u *UnitValueMap) Sort() []string

type UnitValues

type UnitValues []UnitValue

type Web

type Web struct {
	Url   EndPointUrl
	Body  []byte
	Error error
	// contains filtered or unexported fields
}

func (*Web) AppendUrl

func (w *Web) AppendUrl(endpoint string) EndPointUrl

func (*Web) CacheRead

func (w *Web) CacheRead(endpoint EndPoint) ([]byte, error)

CacheRead Retrieves cache data from a local file.

func (*Web) CacheRemove

func (w *Web) CacheRemove(endpoint EndPoint) error

CacheRemove Removes a cache file.

func (*Web) CacheWrite

func (w *Web) CacheWrite(endpoint EndPoint, data []byte) error

CacheWrite Saves cache data to a file path.

func (*Web) CheckCache

func (w *Web) CheckCache(endpoint EndPoint) bool

CheckCache Retrieves cache data from a local file.

func (*Web) Get

func (w *Web) Get(endpoint EndPoint) EndPoint

func (*Web) GetCacheDir

func (w *Web) GetCacheDir() string

func (*Web) GetCacheTimeout

func (w *Web) GetCacheTimeout() time.Duration

func (*Web) SetCacheDir

func (w *Web) SetCacheDir(basedir string) error

func (*Web) SetCacheTimeout

func (w *Web) SetCacheTimeout(duration time.Duration)

func (*Web) SetUrl

func (w *Web) SetUrl(u string) error

Directories

Path Synopsis
Package apiReflect - Snaffooed from https://github.com/fatih/structs
Package apiReflect - Snaffooed from https://github.com/fatih/structs
Package nullEndPoint - This file is auto-generated from the update_all.sh script.
Package nullEndPoint - This file is auto-generated from the update_all.sh script.

Jump to

Keyboard shortcuts

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