Skip to content

Commit

Permalink
added validator and initsession
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Jan 27, 2023
1 parent 1911eda commit 402b3cc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.18
require (
github.com/go-resty/resty/v2 v2.7.0 // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
gopkg.in/validator.v2 v2.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/validator.v2 v2.0.1 h1:xF0KWyGWXm/LM2G1TrEjqOu4pa6coO9AlWSf3msVfDY=
gopkg.in/validator.v2 v2.0.1/go.mod h1:lIUZBlB3Im4s/eYp39Ry/wkR02yOPhZ9IwIRBjuPuG8=
60 changes: 40 additions & 20 deletions haivision/auth.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
package haivision

import (
"encoding/json"

"gopkg.in/validator.v2"
)

/*
Requests
POST /api/session
{
"username" : "[user name]",
"password" : "[password]"
}
{
"username" : "[user name]",
"password" : "[password]"
}
Response
{
"response": {
"type": "Session",
"message": "Session successfully started for haiadmin",
"sessionID": "[Session ID]",
"lastLoginDate": 1536777877871,
"numLoginFailures": 0
}
}
*/
// POST
func (o *Haivision) InitSession(username string, password string) error {
return nil
{
"response": {
"type": "Session",
"message": "Session successfully started for haiadmin",
"sessionID": "[Session ID]",
"lastLoginDate": 1536777877871,
"numLoginFailures": 0
}
}
*/
func (o *Haivision) InitSession(username string, password string) (*ResponseInitSession, error) {
var requestBody RequestInitSession
//
if errs := validator.Validate(requestBody); errs != nil {
// values not valid, deal with errors here
return nil, errs
}
resp, err := o.restyPost(SESSION, requestBody)
if err != nil {
return nil, err
}
var obj ResponseInitSession
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
return &obj, nil
}

// GET
// GET
func (o *Haivision) GetDeviceInfo() error {
return nil
}
return nil
}
12 changes: 6 additions & 6 deletions haivision/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package haivision
import "fmt"

const (
// AUTH
SESSION = "/api/session"
DEVICE_INFO = "/api/devices"
// AUTH
SESSION = "/api/session"
DEVICE_INFO = "/api/devices"
// ROUTES
LIST_ROUTES = "/api/gateway/%s/routes"
//
LIST_ROUTES = "/api/gateway/%s/routes"
//
)

var (
//
GET_LIST_OF_ROUTES = func(deviceId string) string {
return fmt.Sprintf(LIST_ROUTES, deviceId)
}
//
//
)
4 changes: 2 additions & 2 deletions haivision/haivision.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type IHaivisionClient interface {
HealthCheck() error
IsDebug() bool
// auth stuff
InitSession(username string, password string) error
InitSession(username string, password string) (*ResponseInitSession, error)
// Streaming
GetRoutes(deviceId string) error
GetRoutes(deviceId string) error
}

func (o *Haivision) HealthCheck() error {
Expand Down
17 changes: 17 additions & 0 deletions haivision/response.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
package haivision

/*{
"response": {
"type": "Session",
"message": "Session successfully started for haiadmin",
"sessionID": "[Session ID]",
"lastLoginDate": 1536777877871,
"numLoginFailures": 0
}
}*/

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"`
}

0 comments on commit 402b3cc

Please sign in to comment.