Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package serviceportsinformation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
func (c *ServicePortsInformation) GetPorts() (map[string]int, []int) {
|
||||
req := ServicePortsInformationRequest{Type: "servicePortsInformationRequest", UUID: "UUID"}
|
||||
|
||||
c.Websocket.WriteJSON(req)
|
||||
|
||||
var res ServicePortsInformationResponse
|
||||
err := c.Websocket.ReadJSON(&res)
|
||||
if err != nil {
|
||||
log.Fatal("ServicePortsInformationRequest - Error getting service ports information:", err)
|
||||
}
|
||||
|
||||
var exerciseServicePortMap map[string]int = make(map[string]int)
|
||||
for _, exercise := range res.Data {
|
||||
for _, service := range exercise.Services {
|
||||
for _, port := range service.Ports {
|
||||
log.Printf("%d-%s%d\n", exercise.ExerciseID, service.Name, port.TypeID)
|
||||
exerciseServicePortMap[fmt.Sprintf("%d-%s%d", exercise.ExerciseID, service.Name, port.TypeID)] = port.Number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var excerciseIds []int
|
||||
for _, exercise := range res.Data {
|
||||
excerciseIds = append(excerciseIds, exercise.ExerciseID)
|
||||
}
|
||||
|
||||
c.Websocket.Close()
|
||||
|
||||
return exerciseServicePortMap, excerciseIds
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package serviceportsinformation
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type ServicePortsInformation struct {
|
||||
Websocket *websocket.Conn
|
||||
}
|
||||
|
||||
type ServicePortsInformationRequest struct {
|
||||
Type string `json:"type"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
|
||||
type ServicePortsInformationResponse struct {
|
||||
Data []struct {
|
||||
ExerciseID int `json:"exerciseId"`
|
||||
ReplayPartitionID int `json:"replayPartitionId"`
|
||||
Services []struct {
|
||||
Name string `json:"name"`
|
||||
NameAbbrevation string `json:"nameAbbrevation"`
|
||||
Ports []struct {
|
||||
Number int `json:"number"`
|
||||
Properties string `json:"properties"`
|
||||
TypeID int `json:"typeId"`
|
||||
} `json:"ports"`
|
||||
} `json:"services"`
|
||||
} `json:"data"`
|
||||
Type string `json:"type"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
Reference in new issue
Block a user