From adaf60730c354012434cdbb0be40630736db772d Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 3 Jun 2021 18:42:06 +0200 Subject: [PATCH 1/9] Factored json output and added Error field --- main.go | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 69041a3..011a3a3 100644 --- a/main.go +++ b/main.go @@ -50,27 +50,39 @@ func main() { cmd = strings.ToUpper(strings.TrimSpace(cmd)) switch cmd { case "START": - outputMessage("start", "OK") + output(&genericMessageJSON{ + EventType: "start", + Message: "OK", + }) case "STOP": if syncStarted { syncCloseChan <- true syncStarted = false } - outputMessage("stop", "OK") + output(&genericMessageJSON{ + EventType: "stop", + Message: "OK", + }) case "LIST": outputList() case "QUIT": - outputMessage("quit", "OK") + output(&genericMessageJSON{ + EventType: "quit", + Message: "OK", + }) os.Exit(0) case "START_SYNC": if syncStarted { - outputMessage("startSync", "OK") } else if close, err := startSync(); err != nil { outputError(err) } else { syncCloseChan = close syncStarted = true } + output(&genericMessageJSON{ + EventType: "start_sync", + Message: "OK", + }) default: outputError(fmt.Errorf("Command %s not supported", cmd)) } @@ -135,16 +147,14 @@ func newBoardPortJSON(port *enumerator.PortDetails) *boardPortJSON { return portJSON } -type messageOutputJSON struct { +type genericMessageJSON struct { EventType string `json:"eventType"` + Error bool `json:"error,omitempty"` Message string `json:"message"` } -func outputMessage(eventType, message string) { - d, err := json.MarshalIndent(&messageOutputJSON{ - EventType: eventType, - Message: message, - }, "", " ") +func output(msg interface{}) { + d, err := json.MarshalIndent(msg, "", " ") if err != nil { outputError(err) } else { @@ -153,7 +163,11 @@ func outputMessage(eventType, message string) { } func outputError(err error) { - outputMessage("error", err.Error()) + output(&genericMessageJSON{ + EventType: "command_error", + Error: true, + Message: err.Error(), + }) } var stdoutMutext sync.Mutex From 0b87821e2b340576c6b09f14091f4e52cc7aecaf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 01:05:29 +0200 Subject: [PATCH 2/9] Implemented HELLO cmd --- main.go | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 011a3a3..a0acaac 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,8 @@ import ( "encoding/json" "fmt" "os" + "regexp" + "strconv" "strings" "sync" @@ -42,13 +44,42 @@ func main() { reader := bufio.NewReader(os.Stdin) for { - cmd, err := reader.ReadString('\n') + fullCmd, err := reader.ReadString('\n') if err != nil { outputError(err) os.Exit(1) } - cmd = strings.ToUpper(strings.TrimSpace(cmd)) + split := strings.Split(fullCmd, " ") + cmd := strings.ToUpper(strings.TrimSpace(split[0])) switch cmd { + case "HELLO": + re := regexp.MustCompile(`(\d+) "([^"]+)"`) + matches := re.FindStringSubmatch(fullCmd[6:]) + if len(matches) != 3 { + output(&genericMessageJSON{ + EventType: "command_error", + Error: true, + Message: "Invalid HELLO command", + }) + continue + } + // userAgent := matches[2] + // reqProtocolVersion, err := strconv.ParseUint(matches[1], 10, 64) + _, err := strconv.ParseUint(matches[1], 10, 64) + if err != nil { + output(&genericMessageJSON{ + EventType: "command_error", + Error: true, + Message: "Invalid protocol version: " + matches[2], + }) + } + // fmt.Println("User agent:", userAgent) + // fmt.Println("Req. Protocol version:", reqProtocolVersion) + output(&helloMessageJSON{ + EventType: "hello", + ProtocolVersion: "1", // Protocol version 1 is the only supported for now... + Message: "OK", + }) case "START": output(&genericMessageJSON{ EventType: "start", @@ -147,6 +178,12 @@ func newBoardPortJSON(port *enumerator.PortDetails) *boardPortJSON { return portJSON } +type helloMessageJSON struct { + EventType string `json:"eventType"` + ProtocolVersion string `json:"protocolVersion"` + Message string `json:"message"` +} + type genericMessageJSON struct { EventType string `json:"eventType"` Error bool `json:"error,omitempty"` From 51184d9e61b3d25ef06d78bf644acb9456cd942f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 01:23:04 +0200 Subject: [PATCH 3/9] Implemented ERROR protocol --- main.go | 54 ++++++++++++++++++++++++++++--------------------- sync.go | 11 ---------- sync_darwin.go | 16 +++++++++++---- sync_linux.go | 18 +++++++++++++---- sync_windows.go | 10 ++++++--- 5 files changed, 64 insertions(+), 45 deletions(-) diff --git a/main.go b/main.go index a0acaac..8de1f9c 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,11 @@ func main() { for { fullCmd, err := reader.ReadString('\n') if err != nil { - outputError(err) + output(&genericMessageJSON{ + EventType: "command_error", + Error: true, + Message: err.Error(), + }) os.Exit(1) } split := strings.Split(fullCmd, " ") @@ -104,18 +108,27 @@ func main() { os.Exit(0) case "START_SYNC": if syncStarted { + // sync already started, just acknowledge again... + output(&genericMessageJSON{ + EventType: "start_sync", + Message: "OK", + }) } else if close, err := startSync(); err != nil { - outputError(err) + output(&genericMessageJSON{ + EventType: "start_sync", + Error: true, + Message: err.Error(), + }) } else { syncCloseChan = close syncStarted = true } + default: output(&genericMessageJSON{ - EventType: "start_sync", - Message: "OK", + EventType: "command_error", + Error: true, + Message: fmt.Sprintf("Command %s not supported", cmd), }) - default: - outputError(fmt.Errorf("Command %s not supported", cmd)) } } } @@ -137,7 +150,11 @@ type listOutputJSON struct { func outputList() { list, err := enumerator.GetDetailedPortsList() if err != nil { - outputError(err) + output(&genericMessageJSON{ + EventType: "list", + Error: true, + Message: err.Error(), + }) return } portsJSON := []*boardPortJSON{} @@ -145,15 +162,10 @@ func outputList() { portJSON := newBoardPortJSON(port) portsJSON = append(portsJSON, portJSON) } - d, err := json.MarshalIndent(&listOutputJSON{ + output(&listOutputJSON{ EventType: "list", Ports: portsJSON, - }, "", " ") - if err != nil { - outputError(err) - return - } - syncronizedPrintLn(string(d)) + }) } func newBoardPortJSON(port *enumerator.PortDetails) *boardPortJSON { @@ -193,20 +205,16 @@ type genericMessageJSON struct { func output(msg interface{}) { d, err := json.MarshalIndent(msg, "", " ") if err != nil { - outputError(err) + output(&genericMessageJSON{ + EventType: "command_error", + Error: true, + Message: err.Error(), + }) } else { syncronizedPrintLn(string(d)) } } -func outputError(err error) { - output(&genericMessageJSON{ - EventType: "command_error", - Error: true, - Message: err.Error(), - }) -} - var stdoutMutext sync.Mutex func syncronizedPrintLn(a ...interface{}) { diff --git a/sync.go b/sync.go index 5cadc52..272e614 100644 --- a/sync.go +++ b/sync.go @@ -17,18 +17,7 @@ package main -import "encoding/json" - type syncOutputJSON struct { EventType string `json:"eventType"` Port *boardPortJSON `json:"port"` } - -func outputSyncMessage(message *syncOutputJSON) { - d, err := json.MarshalIndent(message, "", " ") - if err != nil { - outputError(err) - } else { - syncronizedPrintLn(string(d)) - } -} diff --git a/sync_darwin.go b/sync_darwin.go index a00614c..5f4892d 100644 --- a/sync_darwin.go +++ b/sync_darwin.go @@ -52,8 +52,12 @@ func startSync() (chan<- bool, error) { if err != nil { return nil, err } + output(&genericMessageJSON{ + EventType: "start_sync", + Message: "OK", + }) for _, port := range current { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) @@ -100,7 +104,11 @@ func startSync() (chan<- bool, error) { continue } if err != nil { - outputError(fmt.Errorf("error decoding START_SYNC event: %s", err)) + output(&genericMessageJSON{ + EventType: "start_sync", + Error: true, + Message: fmt.Sprintf("error decoding START_SYNC event: %s", err), + }) } // if there is an event retry up to 5 times if n > 0 { @@ -115,7 +123,7 @@ func startSync() (chan<- bool, error) { for _, port := range current { if !portListHas(updates, port) { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "remove", Port: &boardPortJSON{Address: port.Name}, }) @@ -124,7 +132,7 @@ func startSync() (chan<- bool, error) { for _, port := range updates { if !portListHas(current, port) { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) diff --git a/sync_linux.go b/sync_linux.go index feac941..02570a4 100644 --- a/sync_linux.go +++ b/sync_linux.go @@ -43,9 +43,14 @@ func startSync() (chan<- bool, error) { syncReader.Close() }() + output(&genericMessageJSON{ + EventType: "start_sync", + Message: "OK", + }) + // Ouput initial port state for _, port := range current { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) @@ -62,7 +67,12 @@ func startSync() (chan<- bool, error) { for { evt, err := dec.Decode() if err != nil { - outputError(fmt.Errorf("error decoding START_SYNC event: %s", err)) + output(&genericMessageJSON{ + EventType: "start_sync", + Error: true, + Message: fmt.Sprintf("error decoding START_SYNC event: %s", err), + }) + // TODO: output "stop" msg? close? return } @@ -77,7 +87,7 @@ func startSync() (chan<- bool, error) { } for _, port := range portList { if port.IsUSB && port.Name == changedPort { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) @@ -86,7 +96,7 @@ func startSync() (chan<- bool, error) { } } if evt.Action == "remove" { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "remove", Port: &boardPortJSON{Address: changedPort}, }) diff --git a/sync_windows.go b/sync_windows.go index 2a60a73..c5b9f08 100644 --- a/sync_windows.go +++ b/sync_windows.go @@ -117,8 +117,12 @@ func startSync() (chan<- bool, error) { fmt.Println(err) return } + output(&genericMessageJSON{ + EventType: "start_sync", + Message: "OK", + }) for _, port := range current { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) @@ -164,7 +168,7 @@ func startSync() (chan<- bool, error) { for _, port := range current { if !portListHas(updates, port) { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "remove", Port: &boardPortJSON{Address: port.Name}, }) @@ -173,7 +177,7 @@ func startSync() (chan<- bool, error) { for _, port := range updates { if !portListHas(current, port) { - outputSyncMessage(&syncOutputJSON{ + output(&syncOutputJSON{ EventType: "add", Port: newBoardPortJSON(port), }) From d70b1fb92aa467306c401c7c72e44f50dfca80c1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 01:27:11 +0200 Subject: [PATCH 4/9] Port does not have identification properties anymore --- main.go | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 8de1f9c..254484a 100644 --- a/main.go +++ b/main.go @@ -134,12 +134,11 @@ func main() { } type boardPortJSON struct { - Address string `json:"address"` - Label string `json:"label,omitempty"` - Prefs *properties.Map `json:"prefs,omitempty"` - IdentificationPrefs *properties.Map `json:"identificationPrefs,omitempty"` - Protocol string `json:"protocol,omitempty"` - ProtocolLabel string `json:"protocolLabel,omitempty"` + Address string `json:"address"` + Label string `json:"label,omitempty"` + Protocol string `json:"protocol,omitempty"` + ProtocolLabel string `json:"protocolLabel,omitempty"` + Properties *properties.Map `json:"properties,omitempty"` } type listOutputJSON struct { @@ -170,22 +169,18 @@ func outputList() { func newBoardPortJSON(port *enumerator.PortDetails) *boardPortJSON { prefs := properties.NewMap() - identificationPrefs := properties.NewMap() portJSON := &boardPortJSON{ - Address: port.Name, - Label: port.Name, - Protocol: "serial", - ProtocolLabel: "Serial Port", - Prefs: prefs, - IdentificationPrefs: identificationPrefs, + Address: port.Name, + Label: port.Name, + Protocol: "serial", + ProtocolLabel: "Serial Port", + Properties: prefs, } if port.IsUSB { portJSON.ProtocolLabel = "Serial Port (USB)" - portJSON.Prefs.Set("vendorId", "0x"+port.VID) - portJSON.Prefs.Set("productId", "0x"+port.PID) - portJSON.Prefs.Set("serialNumber", port.SerialNumber) - portJSON.IdentificationPrefs.Set("pid", "0x"+port.PID) - portJSON.IdentificationPrefs.Set("vid", "0x"+port.VID) + portJSON.Properties.Set("vid", "0x"+port.VID) + portJSON.Properties.Set("pid", "0x"+port.PID) + portJSON.Properties.Set("serialNumber", port.SerialNumber) } return portJSON } From f1fd9f3a8a0c97626cacf09feb944099f535c460 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 01:29:51 +0200 Subject: [PATCH 5/9] Report protocol on 'remove' event --- sync_darwin.go | 5 ++++- sync_linux.go | 5 ++++- sync_windows.go | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sync_darwin.go b/sync_darwin.go index 5f4892d..1f40547 100644 --- a/sync_darwin.go +++ b/sync_darwin.go @@ -125,7 +125,10 @@ func startSync() (chan<- bool, error) { if !portListHas(updates, port) { output(&syncOutputJSON{ EventType: "remove", - Port: &boardPortJSON{Address: port.Name}, + Port: &boardPortJSON{ + Address: port.Name, + Protocol: "serial", + }, }) } } diff --git a/sync_linux.go b/sync_linux.go index 02570a4..d12d7e1 100644 --- a/sync_linux.go +++ b/sync_linux.go @@ -98,7 +98,10 @@ func startSync() (chan<- bool, error) { if evt.Action == "remove" { output(&syncOutputJSON{ EventType: "remove", - Port: &boardPortJSON{Address: changedPort}, + Port: &boardPortJSON{ + Address: changedPort, + Protocol: "serial", + }, }) } } diff --git a/sync_windows.go b/sync_windows.go index c5b9f08..cf05cea 100644 --- a/sync_windows.go +++ b/sync_windows.go @@ -170,7 +170,10 @@ func startSync() (chan<- bool, error) { if !portListHas(updates, port) { output(&syncOutputJSON{ EventType: "remove", - Port: &boardPortJSON{Address: port.Name}, + Port: &boardPortJSON{ + Address: port.Name, + Protocol: "serial", + }, }) } } From 87c2119bd831480b00e75935257fca7a1ae1a605 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 01:40:13 +0200 Subject: [PATCH 6/9] Updated readme --- README.md | 124 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index be8977f..1d4ca1a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,35 @@ Install a recent go enviroment (>=13.0) and run `go build`. The executable `seri ## Usage -After startup, the tool waits for commands. The available commands are: `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`. +After startup, the tool waits for commands. The available commands are: `HELLO`, `START`, `STOP`, `QUIT`, `LIST` and `START_SYNC`. + +#### HELLO command + +The `HELLO` command is used to establish the pluggable discovery protocol between client and discovery. +The format of the command is: + +`HELLO ""` + +for example: + +`HELLO 1 "Arduino IDE"` + +or: + +`HELLO 1 "arduino-cli"` + +in this case the protocol version requested by the clien is `1` (at the moment of writing there were no other revisions of the protocol). +The response to the command is: + +```json +{ + "eventType": "hello", + "protocolVersion": "1", + "message": "OK" +} +``` + +`protocolVersion` is the protocol version that the discovery is going to use in the remainder of the communication. #### START command @@ -56,14 +84,10 @@ The `LIST` command returns a list of the currently available serial ports. The f { "address": "/dev/ttyACM0", "label": "/dev/ttyACM0", - "prefs": { - "productId": "0x804e", - "serialNumber": "EBEABFD6514D32364E202020FF10181E", - "vendorId": "0x2341" - }, - "identificationPrefs": { + "properties": { "pid": "0x804e", - "vid": "0x2341" + "vid": "0x2341", + "serialNumber": "EBEABFD6514D32364E202020FF10181E" }, "protocol": "serial", "protocolLabel": "Serial Port (USB)" @@ -72,13 +96,23 @@ The `LIST` command returns a list of the currently available serial ports. The f } ``` -The `ports` field contains a list of the available serial ports. If the serial port comes from an USB serial converter the USB VID/PID and USB SERIAL NUMBER properties are also reported inside `prefs`. Inside the `identificationPrefs` instead we have only the properties useful for product identification (in this case USB VID/PID only that may be useful to identify the board) +The `ports` field contains a list of the available serial ports. If the serial port comes from an USB serial converter the USB VID/PID and USB SERIAL NUMBER properties are also reported inside `properties`. The list command is a one-shot command, if you need continuos monitoring of ports you should use `START_SYNC` command. #### START_SYNC command The `START_SYNC` command puts the tool in "events" mode: the discovery will send `add` and `remove` events each time a new port is detected or removed respectively. +The immediate response to the command is: + +```json +{ + "eventType": "start_sync", + "message": "OK" +} +``` + +after that the discovery enters in "events" mode. The `add` events looks like the following: @@ -88,14 +122,10 @@ The `add` events looks like the following: "port": { "address": "/dev/ttyACM0", "label": "/dev/ttyACM0", - "prefs": { - "productId": "0x804e", - "serialNumber": "EBEABFD6514D32364E202020FF10181E", - "vendorId": "0x2341" - }, - "identificationPrefs": { + "properties": { "pid": "0x804e", - "vid": "0x2341" + "vid": "0x2341", + "serialNumber": "EBEABFD6514D32364E202020FF10181E" }, "protocol": "serial", "protocolLabel": "Serial Port (USB)" @@ -111,47 +141,66 @@ The `remove` event looks like this: { "eventType": "remove", "port": { - "address": "/dev/ttyACM0" + "address": "/dev/ttyACM0", + "protocol": "serial" } } ``` -in this case only the `address` field is reported. +in this case only the `address` and `protocol` fields are reported. ### Example of usage A possible transcript of the discovery usage: ``` -$ ./serial-discovery +$ ./serial-discovery START { "eventType": "start", "message": "OK" } +LIST +{ + "eventType": "list", + "ports": [ + { + "address": "/dev/ttyACM0", + "label": "/dev/ttyACM0", + "protocol": "serial", + "protocolLabel": "Serial Port (USB)", + "properties": { + "pid": "0x004e", + "serialNumber": "EBEABFD6514D32364E202020FF10181E", + "vid": "0x2341" + } + } + ] +} START_SYNC { + "eventType": "start_sync", + "message": "OK" +} +{ <--- this event has been immediately sent "eventType": "add", "port": { "address": "/dev/ttyACM0", "label": "/dev/ttyACM0", - "prefs": { - "productId": "0x804e", + "protocol": "serial", + "protocolLabel": "Serial Port (USB)", + "properties": { + "pid": "0x004e", "serialNumber": "EBEABFD6514D32364E202020FF10181E", - "vendorId": "0x2341" - }, - "identificationPrefs": { - "pid": "0x804e", "vid": "0x2341" - }, - "protocol": "serial", - "protocolLabel": "Serial Port (USB)" + } } } { <--- the board has been disconnected here "eventType": "remove", "port": { - "address": "/dev/ttyACM0" + "address": "/dev/ttyACM0", + "protocol": "serial" } } { <--- the board has been connected again @@ -159,17 +208,13 @@ START_SYNC "port": { "address": "/dev/ttyACM0", "label": "/dev/ttyACM0", - "prefs": { - "productId": "0x804e", + "protocol": "serial", + "protocolLabel": "Serial Port (USB)", + "properties": { + "pid": "0x004e", "serialNumber": "EBEABFD6514D32364E202020FF10181E", - "vendorId": "0x2341" - }, - "identificationPrefs": { - "pid": "0x804e", "vid": "0x2341" - }, - "protocol": "serial", - "protocolLabel": "Serial Port (USB)" + } } } QUIT @@ -196,5 +241,4 @@ The software is released under the GNU General Public License, which covers the of the serial-discovery code. The terms of this license can be found at: https://www.gnu.org/licenses/gpl-3.0.en.html -See [LICENSE.txt]() for details. - +See [LICENSE.txt](https://github.com/arduino/serial-discovery/blob/master/LICENSE.txt) for details. From 3b72f452119cdc3bd35cb55365b51afa27f27fa9 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 4 Jun 2021 16:02:48 +0200 Subject: [PATCH 7/9] Update README.md Co-authored-by: per1234 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d4ca1a..4143528 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ or: `HELLO 1 "arduino-cli"` -in this case the protocol version requested by the clien is `1` (at the moment of writing there were no other revisions of the protocol). +in this case the protocol version requested by the client is `1` (at the moment of writing there were no other revisions of the protocol). The response to the command is: ```json From e45938dc5bd2d4eba21e7892b3b6e8cb53fcaf47 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 8 Jun 2021 16:44:09 +0200 Subject: [PATCH 8/9] Change ProtocolVersion field to int --- README.md | 2 +- main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4143528..1906fac 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The response to the command is: ```json { "eventType": "hello", - "protocolVersion": "1", + "protocolVersion": 1, "message": "OK" } ``` diff --git a/main.go b/main.go index 254484a..3a3432d 100644 --- a/main.go +++ b/main.go @@ -81,7 +81,7 @@ func main() { // fmt.Println("Req. Protocol version:", reqProtocolVersion) output(&helloMessageJSON{ EventType: "hello", - ProtocolVersion: "1", // Protocol version 1 is the only supported for now... + ProtocolVersion: 1, // Protocol version 1 is the only supported for now... Message: "OK", }) case "START": @@ -187,7 +187,7 @@ func newBoardPortJSON(port *enumerator.PortDetails) *boardPortJSON { type helloMessageJSON struct { EventType string `json:"eventType"` - ProtocolVersion string `json:"protocolVersion"` + ProtocolVersion int `json:"protocolVersion"` Message string `json:"message"` } From 497dea06e3aa2dbc1a7678089ee4bb2f5e3a5744 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 8 Jun 2021 16:45:18 +0200 Subject: [PATCH 9/9] Removed commented code --- main.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 3a3432d..7c36747 100644 --- a/main.go +++ b/main.go @@ -67,9 +67,8 @@ func main() { }) continue } - // userAgent := matches[2] - // reqProtocolVersion, err := strconv.ParseUint(matches[1], 10, 64) - _, err := strconv.ParseUint(matches[1], 10, 64) + _ /* userAgent */ = matches[2] + _ /* reqProtocolVersion */, err := strconv.ParseUint(matches[1], 10, 64) if err != nil { output(&genericMessageJSON{ EventType: "command_error", @@ -77,8 +76,6 @@ func main() { Message: "Invalid protocol version: " + matches[2], }) } - // fmt.Println("User agent:", userAgent) - // fmt.Println("Req. Protocol version:", reqProtocolVersion) output(&helloMessageJSON{ EventType: "hello", ProtocolVersion: 1, // Protocol version 1 is the only supported for now...