Skip to content

Commit

Permalink
change InterceptorInit to NewWebSocketDebugger and update its descrip…
Browse files Browse the repository at this point in the history
…tion

use logger in Write
  • Loading branch information
Cath3876 committed Feb 6, 2024
1 parent b369a27 commit d193192
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pkg/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type WSWriter struct {
Type string `json:"Type"`
Value string `json:"Value"`
}
logger logging.Logger
}

// InterceptorInit initializes the interceptor according to input boolean
// The interceptor is set to nil if the user decides to not use the debugger
func InterceptorInit(
// NewWebSocketDebugger initializes the interceptor for a given node and uses the given port for the WebSocket connection
func NewWebSocketDebugger(
ownID t.NodeID,
port string,
) (*eventlog.Recorder, error) {
Expand All @@ -53,7 +53,7 @@ func InterceptorInit(
eventlog.SyncWriteOpt(),
)
if err != nil {
panic(err)
return nil, err
}
return interceptor, err
}
Expand All @@ -75,7 +75,7 @@ func (wsw *WSWriter) Close() error {
// The returned EventList contains the accepted events
func (wsw *WSWriter) Write(list *events.EventList, _ int64) (*events.EventList, error) {
for wsw.conn == nil {
fmt.Println("No connection.")
wsw.logger.Log(logging.LevelInfo, "No connection")
time.Sleep(time.Millisecond * 100)
}
if list.Len() == 0 {
Expand Down Expand Up @@ -137,6 +137,7 @@ func newWSWriter(port string) *WSWriter {
WriteBufferSize: WriteBufferSize,
},
eventSignal: make(chan map[string]string),
logger: logging.ConsoleInfoLogger,
}

http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion samples/pingpong/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
fmt.Println("Node ID must be provided in debug mode")
os.Exit(1)
}
interceptor, err = debugger.InterceptorInit(ownID, *debugPort) // replace ownID with port number
interceptor, err = debugger.NewWebSocketDebugger(ownID, *debugPort) // replace ownID with port number
if err != nil {
panic(err)
}
Expand Down

0 comments on commit d193192

Please sign in to comment.