Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5e2161e

Browse filesBrowse files
committed
refactor: rename 'hub' and 'serialhub' types to 'Hub' and 'Serialhub' for consistency
1 parent 99f8235 commit 5e2161e
Copy full SHA for 5e2161e

File tree

Expand file treeCollapse file tree

5 files changed

+27
-27
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+27
-27
lines changed

‎conn.go

Copy file name to clipboardExpand all lines: conn.go
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type Upload struct {
8080

8181
var uploadStatusStr = "ProgrammerStatus"
8282

83-
func uploadHandler(h *hub, pubKey *rsa.PublicKey) func(*gin.Context) {
83+
func uploadHandler(h *Hub, pubKey *rsa.PublicKey) func(*gin.Context) {
8484
return func(c *gin.Context) {
8585
data := new(Upload)
8686
if err := c.BindJSON(data); err != nil {
@@ -193,7 +193,7 @@ func uploadHandler(h *hub, pubKey *rsa.PublicKey) func(*gin.Context) {
193193
// PLogger sends the info from the upload to the websocket
194194
type PLogger struct {
195195
Verbose bool
196-
h *hub
196+
h *Hub
197197
}
198198

199199
// Debug only sends messages if verbose is true (always true for now)
@@ -210,12 +210,12 @@ func (l PLogger) Info(args ...interface{}) {
210210
send(l.h, map[string]string{uploadStatusStr: "Busy", "Msg": output})
211211
}
212212

213-
func send(h *hub, args map[string]string) {
213+
func send(h *Hub, args map[string]string) {
214214
mapB, _ := json.Marshal(args)
215215
h.broadcastSys <- mapB
216216
}
217217

218-
func wsHandler(h *hub) *WsServer {
218+
func wsHandler(h *Hub) *WsServer {
219219
server, err := socketio.NewServer(nil)
220220
if err != nil {
221221
log.Fatal(err)

‎hub.go

Copy file name to clipboardExpand all lines: hub.go
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
log "github.com/sirupsen/logrus"
3030
)
3131

32-
type hub struct {
32+
type Hub struct {
3333
// Registered connections.
3434
connections map[*connection]bool
3535

@@ -47,15 +47,15 @@ type hub struct {
4747

4848
//TODO globals clients
4949
// Serial hub to communicate with serial ports
50-
serialHub *serialhub
50+
serialHub *Serialhub
5151

5252
serialPortList *SerialPortList
5353
}
5454

5555
// NewHub creates a hub that acts as a central hub for handling
5656
// WebSocket connections, broadcasting messages, and processing commands.
57-
func NewHub(serialhub *serialhub, serialList *SerialPortList) *hub {
58-
hub := &hub{
57+
func NewHub(serialhub *Serialhub, serialList *SerialPortList) *Hub {
58+
hub := &Hub{
5959
broadcast: make(chan []byte, 1000),
6060
broadcastSys: make(chan []byte, 1000),
6161
register: make(chan *connection),
@@ -102,15 +102,15 @@ const commands = `{
102102
]
103103
}`
104104

105-
func (h *hub) unregisterConnection(c *connection) {
105+
func (h *Hub) unregisterConnection(c *connection) {
106106
if _, contains := h.connections[c]; !contains {
107107
return
108108
}
109109
delete(h.connections, c)
110110
close(c.send)
111111
}
112112

113-
func (h *hub) sendToRegisteredConnections(data []byte) {
113+
func (h *Hub) sendToRegisteredConnections(data []byte) {
114114
for c := range h.connections {
115115
select {
116116
case c.send <- data:
@@ -123,7 +123,7 @@ func (h *hub) sendToRegisteredConnections(data []byte) {
123123
}
124124
}
125125

126-
func (h *hub) run() {
126+
func (h *Hub) run() {
127127
for {
128128
select {
129129
case c := <-h.register:
@@ -146,7 +146,7 @@ func (h *hub) run() {
146146
}
147147
}
148148

149-
func (h *hub) checkCmd(m []byte) {
149+
func (h *Hub) checkCmd(m []byte) {
150150
//log.Print("Inside checkCmd")
151151
s := string(m[:])
152152

@@ -284,23 +284,23 @@ func logAction(sl string) {
284284
}
285285
}
286286

287-
func (h *hub) memoryStats() {
287+
func (h *Hub) memoryStats() {
288288
var memStats runtime.MemStats
289289
runtime.ReadMemStats(&memStats)
290290
json, _ := json.Marshal(memStats)
291291
log.Printf("memStats:%v\n", string(json))
292292
h.broadcastSys <- json
293293
}
294294

295-
func (h *hub) getHostname() {
295+
func (h *Hub) getHostname() {
296296
h.broadcastSys <- []byte("{\"Hostname\" : \"" + *hostname + "\"}")
297297
}
298298

299-
func (h *hub) getVersion() {
299+
func (h *Hub) getVersion() {
300300
h.broadcastSys <- []byte("{\"Version\" : \"" + version + "\"}")
301301
}
302302

303-
func (h *hub) garbageCollection() {
303+
func (h *Hub) garbageCollection() {
304304
log.Printf("Starting garbageCollection()\n")
305305
h.broadcastSys <- []byte("{\"gc\":\"starting\"}")
306306
h.memoryStats()

‎info.go

Copy file name to clipboardExpand all lines: info.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func infoHandler(c *gin.Context) {
4141
})
4242
}
4343

44-
func pauseHandler(h *hub, s *systray.Systray) func(c *gin.Context) {
44+
func pauseHandler(h *Hub, s *systray.Systray) func(c *gin.Context) {
4545
return func(c *gin.Context) {
4646
go func() {
4747
ports, _ := serial.GetPortsList()

‎serial.go

Copy file name to clipboardExpand all lines: serial.go
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/sirupsen/logrus"
3030
)
3131

32-
type serialhub struct {
32+
type Serialhub struct {
3333
// Opened serial ports.
3434
ports map[*serport]bool
3535
mu sync.Mutex
@@ -40,8 +40,8 @@ type serialhub struct {
4040

4141
// NewSerialHub creates a new serial hub
4242
// It is used to manage serial ports and their connections.
43-
func NewSerialHub() *serialhub {
44-
return &serialhub{
43+
func NewSerialHub() *Serialhub {
44+
return &Serialhub{
4545
ports: make(map[*serport]bool),
4646
}
4747
}
@@ -75,7 +75,7 @@ type SpPortItem struct {
7575
}
7676

7777
// Register serial ports from the connections.
78-
func (sh *serialhub) Register(port *serport) {
78+
func (sh *Serialhub) Register(port *serport) {
7979
sh.mu.Lock()
8080
//log.Print("Registering a port: ", p.portConf.Name)
8181
sh.OnRegister(port)
@@ -84,7 +84,7 @@ func (sh *serialhub) Register(port *serport) {
8484
}
8585

8686
// Unregister requests from connections.
87-
func (sh *serialhub) Unregister(port *serport) {
87+
func (sh *Serialhub) Unregister(port *serport) {
8888
sh.mu.Lock()
8989
//log.Print("Unregistering a port: ", p.portConf.Name)
9090
sh.OnUnregister(port)
@@ -94,7 +94,7 @@ func (sh *serialhub) Unregister(port *serport) {
9494
sh.mu.Unlock()
9595
}
9696

97-
func (sh *serialhub) FindPortByName(portname string) (*serport, bool) {
97+
func (sh *Serialhub) FindPortByName(portname string) (*serport, bool) {
9898
sh.mu.Lock()
9999
defer sh.mu.Unlock()
100100

@@ -265,13 +265,13 @@ func (sp *SerialPortList) getPortByName(portname string) *SpPortItem {
265265
return nil
266266
}
267267

268-
func (h *hub) spErr(err string) {
268+
func (h *Hub) spErr(err string) {
269269
//log.Println("Sending err back: ", err)
270270
//sh.hub.broadcastSys <- []byte(err)
271271
h.broadcastSys <- []byte("{\"Error\" : \"" + err + "\"}")
272272
}
273273

274-
func (h *hub) spClose(portname string) {
274+
func (h *Hub) spClose(portname string) {
275275
if myport, ok := h.serialHub.FindPortByName(portname); ok {
276276
h.broadcastSys <- []byte("Closing serial port " + portname)
277277
myport.Close()
@@ -280,7 +280,7 @@ func (h *hub) spClose(portname string) {
280280
}
281281
}
282282

283-
func (h *hub) spWrite(arg string) {
283+
func (h *Hub) spWrite(arg string) {
284284
// we will get a string of comXX asdf asdf asdf
285285
//log.Println("Inside spWrite arg: " + arg)
286286
arg = strings.TrimPrefix(arg, " ")

‎serialport.go

Copy file name to clipboardExpand all lines: serialport.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (p *serport) writerRaw() {
287287
p.OnMessage([]byte(msgstr))
288288
}
289289

290-
func (h *hub) spHandlerOpen(portname string, baud int, buftype string) {
290+
func (h *Hub) spHandlerOpen(portname string, baud int, buftype string) {
291291

292292
log.Print("Inside spHandler")
293293

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.