Skip to content

Commit b0e9d0a

Browse files
committed
Use pointers in ports lists
1 parent 8b32baf commit b0e9d0a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

serial.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ func updateSerialPortList() {
164164
// TODO: report error?
165165

166166
// Empty port list if they can not be detected
167-
ports = []OsSerialPort{}
167+
ports = []*OsSerialPort{}
168168
}
169169
list := spListDual(ports)
170170
serialPorts.Mu.Lock()
171171
serialPorts.Ports = list
172172
serialPorts.Mu.Unlock()
173173
}
174174

175-
func spListDual(list []OsSerialPort) []SpPortItem {
175+
func spListDual(list []*OsSerialPort) []SpPortItem {
176176
// we have a full clean list of ports now. iterate thru them
177177
// to append the open/close state, baud rates, etc to make
178178
// a super clean nice list to send back to browser

seriallist.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ type OsSerialPort struct {
3838
}
3939

4040
// enumerateSerialPorts will return the OS serial port
41-
func enumerateSerialPorts() ([]OsSerialPort, error) {
41+
func enumerateSerialPorts() ([]*OsSerialPort, error) {
4242
// will timeout in 2 seconds
43-
arrPorts := []OsSerialPort{}
43+
arrPorts := []*OsSerialPort{}
4444
ports, err := enumerator.GetDetailedPortsList()
4545
if err != nil {
4646
return arrPorts, err
@@ -53,14 +53,19 @@ func enumerateSerialPorts() ([]OsSerialPort, error) {
5353
vidString := fmt.Sprintf("0x%s", vid)
5454
pidString := fmt.Sprintf("0x%s", pid)
5555
if vid != "0000" && pid != "0000" {
56-
arrPorts = append(arrPorts, OsSerialPort{Name: element.Name, IDVendor: vidString, IDProduct: pidString, ISerial: element.SerialNumber})
56+
arrPorts = append(arrPorts, &OsSerialPort{
57+
Name: element.Name,
58+
IDVendor: vidString,
59+
IDProduct: pidString,
60+
ISerial: element.SerialNumber,
61+
})
5762
}
5863
}
5964
}
6065

6166
// see if we should filter the list
6267
if portsFilter != nil {
63-
arrPorts = slices.DeleteFunc(arrPorts, func(port OsSerialPort) bool {
68+
arrPorts = slices.DeleteFunc(arrPorts, func(port *OsSerialPort) bool {
6469
match := portsFilter.MatchString(port.Name)
6570
if !match {
6671
log.Debugf("ignoring port not matching filter. port: %v\n", port)

0 commit comments

Comments
 (0)