Skip to content

Commit

Permalink
more readable the code
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Jan 27, 2023
1 parent 2bb86ee commit a06312a
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 107 deletions.
9 changes: 5 additions & 4 deletions haivision/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"gopkg.in/validator.v2"

"github.com/Allan-Nava/Haivision-go-sdk/haivision/device"
"github.com/Allan-Nava/Haivision-go-sdk/haivision/session"
)

Expand All @@ -29,7 +30,7 @@ Response
}
}
*/
func (o *Haivision) InitSession(username string, password string) (*BaseResponseInitSession, error) {
func (o *Haivision) InitSession(username string, password string) (*session.BaseResponseInitSession, error) {
var requestBody session.RequestInitSession
//
if errs := validator.Validate(requestBody); errs != nil {
Expand All @@ -40,7 +41,7 @@ func (o *Haivision) InitSession(username string, password string) (*BaseResponse
if err != nil {
return nil, err
}
var obj BaseResponseInitSession
var obj session.BaseResponseInitSession
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
Expand Down Expand Up @@ -73,12 +74,12 @@ Response
]
*/
func (o *Haivision) GetDeviceInfo() (*BaseResponseDeviceInfo, error) {
func (o *Haivision) GetDeviceInfo() (*device.BaseResponseDeviceInfo, error) {
resp, err := o.restyGet(DEVICE_INFO, nil)
if err != nil {
return nil, err
}
var obj BaseResponseDeviceInfo
var obj device.BaseResponseDeviceInfo
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions haivision/device/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package device
39 changes: 39 additions & 0 deletions haivision/device/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package device

type BaseResponseDeviceInfo struct {
Responses []ResponseDeviceInfo
}

/*
{
"_id": "[Device ID]",
"type": "gateway",
"ip": "127.0.0.1",
"name": "Haivision Gateway",
"lastConnectedAt": [Date/time shown in Unix time],
"statusCode": "ok",
"status": "Online",
"statusDetails": "Connection has been established in the last 1 minutes.",
"serialNumber": null,
"firmware": "5.0.180611.1530",
"hasAdminError": false,
"pendingSync": false,
"lastConnection": "<1m"
}
*/
type ResponseDeviceInfo struct {
ID string `json:"_id" validate:"nonzero"`
Type string `json:"type" validate:"nonzero"`
IP string `json:"ip" validate:"nonzero"`
Name string `json:"name" validate:"nonzero"`
LastConnectedAt int64 `json:"lastConnectedAt" validate:"nonzero"`
StatusCode string `json:"statusCode" validate:"nonzero"`
Status string `json:"status" validate:"nonzero"`
StatusDetails string `json:"statusDetails" validate:"nonzero"`
SerialNumber string `json:"serialNumber" validate:"nonzero"`
Firmware string `json:"firmware" validate:"nonzero"`
HasAdminError bool `json:"hasAdminError" validate:"nonzero"`
PendingSync bool `json:"pendingSync" validate:"nonzero"`
LastConnection string `json:"lastConnection" validate:"nonzero"`
LastConnectionAt string `json:"lastConnectionAt" validate:"nonzero"`
}
8 changes: 5 additions & 3 deletions haivision/haivision.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"strings"

"github.com/Allan-Nava/Haivision-go-sdk/haivision/device"
"github.com/Allan-Nava/Haivision-go-sdk/haivision/session"
"github.com/go-resty/resty/v2"
)

Expand All @@ -18,9 +20,9 @@ type IHaivisionClient interface {
HealthCheck() error
IsDebug() bool
// auth stuff
InitSession(username string, password string) (*BaseResponseInitSession, error)
GetSessionInfo() (*ResponseSessionInfo, error)
GetDeviceInfo() (*BaseResponseDeviceInfo, error)
InitSession(username string, password string) (*session.BaseResponseInitSession, error)
GetSessionInfo() (*session.ResponseSessionInfo, error)
GetDeviceInfo() (*device.BaseResponseDeviceInfo, error)
// Streaming
GetRoutes(deviceId string) error
// CreateRoute() error
Expand Down
11 changes: 0 additions & 11 deletions haivision/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ type RequestSourceModelUDPandRTP struct {
Fec string `json:"fec" required:"true" validate:"nonnil,min=1"`
}

// https://doc.haivision.com/HMG3.7.5/rest-api-integrator-s-reference/rest-api-reference/object-model-reference/source-object-model?activetab=SRT%7EUDPandRTP

type RequestSourceModelSRT struct {
Name string `json:"name" required:"true" validate:"nonnil,min=1"`
ID string `json:"id" required:"true" validate:"nonnil,min=1"`
Address string `json:"address" required:"true" validate:"nonnil,min=1"`
Protocol string `json:"protocol" required:"true" validate:"nonnil,min=1"`
Port int `json:"port" required:"true" validate:"nonnil,min=1"`
NetworkInterface string `json:"networkInterface" required:"true" validate:"nonnil,min=1"`
}

/*
{
"action": "create",
Expand Down
89 changes: 0 additions & 89 deletions haivision/response.go

This file was deleted.

50 changes: 50 additions & 0 deletions haivision/session/response.go
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
package session

/*
{
"response": {
"type": "Session",
"message": "Session successfully started for haiadmin",
"sessionID": "[Session ID]",
"lastLoginDate": 1536777877871,
"numLoginFailures": 0
}
}
*/
type BaseResponseInitSession struct {
Response ResponseInitSession `json:"response" validate:"nonzero"`
}

type ResponseInitSession struct {
Type string `json:"type" validate:"nonzero"`
Message string `json:"message" validate:"nonzero"`
SessionID string `json:"sessionID" validate:"nonzero"`
LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"`
NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"`
}

/*
{
"sessionID": "[Session ID]",
"displayName": "Administrator",
"email": "haiadmin@localhost",
"roles": [
"Administrator"
],
"startAt": 1536937838919,
"expireAt": 1536938857529,
"lastLoginDate": null,
"numLoginFailures": null,
"isLicensed": true
}
*/
type ResponseSessionInfo struct {
SessionID string `json:"sessionID" validate:"nonzero"`
DisplayName string `json:"displayName" validate:"nonzero"`
Email string `json:"email" validate:"nonzero"`
Roles []string `json:"roles" validate:"nonzero"`
StartAt int64 `json:"startAt" validate:"nonzero"`
ExpireAt int64 `json:"expireAt" validate:"nonzero"`
LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"`
NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"`
IsLicensed bool `json:"isLicensed" validate:"nonzero"`
}
11 changes: 11 additions & 0 deletions haivision/srt/request.go
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
package srt

// https://doc.haivision.com/HMG3.7.5/rest-api-integrator-s-reference/rest-api-reference/object-model-reference/source-object-model?activetab=SRT%7EUDPandRTP

type RequestSourceModelSRT struct {
Name string `json:"name" required:"true" validate:"nonnil,min=1"`
ID string `json:"id" required:"true" validate:"nonnil,min=1"`
Address string `json:"address" required:"true" validate:"nonnil,min=1"`
Protocol string `json:"protocol" required:"true" validate:"nonnil,min=1"`
Port int `json:"port" required:"true" validate:"nonnil,min=1"`
NetworkInterface string `json:"networkInterface" required:"true" validate:"nonnil,min=1"`
}

0 comments on commit a06312a

Please sign in to comment.