mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-24 19:47:38 +00:00
WIP
This commit is contained in:
7
shared/go.mod
Normal file
7
shared/go.mod
Normal file
@@ -0,0 +1,7 @@
|
||||
module github.com/up9inc/mizu/shared
|
||||
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
)
|
22
shared/models.go
Normal file
22
shared/models.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package shared
|
||||
|
||||
type ControlSocketMessageType string
|
||||
|
||||
const (
|
||||
TAPPING_STATUS_MESSAGE_TYPE ControlSocketMessageType = "tappingStatus"
|
||||
)
|
||||
|
||||
type ControlSocketMessage struct {
|
||||
MessageType ControlSocketMessageType `json:"messageType"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type TapStatus struct {
|
||||
Namespace string `json:"namespace"`
|
||||
Pods []PodInfo `json:"pods"`
|
||||
}
|
||||
|
||||
type PodInfo struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
33
shared/socket_client.go
Normal file
33
shared/socket_client.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ConnectToSocketServer(address string) (*websocket.Conn, error) {
|
||||
const maxTry = 5
|
||||
const sleepTime = time.Second * 2
|
||||
var err error
|
||||
var connection *websocket.Conn
|
||||
try := 0
|
||||
|
||||
// Connection to server fails if client pod is up before server.
|
||||
// Retries solve this issue.
|
||||
for try < maxTry {
|
||||
connection, _, err = websocket.DefaultDialer.Dial(address, nil)
|
||||
if err != nil {
|
||||
try++
|
||||
// fmt.Printf("Failed connecting to websocket server: %s, (%v,%+v)\n", err, err, err)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return connection, nil
|
||||
}
|
Reference in New Issue
Block a user