Skip to content

Commit 8f20972

Browse files
committed
fix task go:lint
1 parent 9e748df commit 8f20972

34 files changed

+2285
-2251
lines changed

Taskfile.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ tasks:
3030
desc: Build the project, to use a specific version use `task build TAG_VERSION=x.x.x`
3131
dir: "{{.DEFAULT_GO_MODULE_PATH}}"
3232
cmds:
33-
- go build -v -i {{default "" .ADDITIONAL_FLAGS}} -o {{default "arduino-create-agent" .APP_NAME}} -ldflags '-X main.version={{default .TAG_TEST .TAG_VERSION}} -X main.git_revision={{.COMMIT}} {{default "" .WIN_FLAGS}}'
33+
- go build -v -i {{default "" .ADDITIONAL_FLAGS}} -o {{default "arduino-create-agent" .APP_NAME}} -ldflags '-X main.version={{default .TAG_TEST .TAG_VERSION}} -X main.commit={{.COMMIT}} {{default "" .WIN_FLAGS}}'
3434
vars:
3535
COMMIT:
3636
sh: git log -n 1 --format=%h

bufferflow.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package main
1717

18+
// Bufferflow interface
1819
type Bufferflow interface {
1920
Init()
2021
OnIncomingData(data string) // implement this method

bufferflow_default.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
log "github.com/sirupsen/logrus"
2222
)
2323

24+
// BufferflowDefault is the default bufferflow, whick means no buffering
2425
type BufferflowDefault struct {
2526
port string
2627
output chan<- []byte
2728
input chan string
2829
done chan bool
2930
}
3031

32+
// NewBufferflowDefault create a new default bufferflow
3133
func NewBufferflowDefault(port string, output chan<- []byte) *BufferflowDefault {
3234
return &BufferflowDefault{
3335
port: port,
@@ -37,6 +39,7 @@ func NewBufferflowDefault(port string, output chan<- []byte) *BufferflowDefault
3739
}
3840
}
3941

42+
// Init will initialize the bufferflow
4043
func (b *BufferflowDefault) Init() {
4144
log.Println("Initting default buffer flow (which means no buffering)")
4245
go b.consumeInput()
@@ -57,10 +60,12 @@ Loop:
5760
close(b.input) // close the input channel at the end of the computation
5861
}
5962

63+
// OnIncomingData will forward the data
6064
func (b *BufferflowDefault) OnIncomingData(data string) {
6165
b.input <- data
6266
}
6367

68+
// Close will close the bufferflow
6469
func (b *BufferflowDefault) Close() {
6570
b.done <- true
6671
close(b.done)

bufferflow_timed.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
log "github.com/sirupsen/logrus"
2323
)
2424

25+
// BufferflowTimed sends data once every 16ms
2526
type BufferflowTimed struct {
2627
port string
2728
output chan<- []byte
@@ -32,6 +33,7 @@ type BufferflowTimed struct {
3233
bufferedOutput string
3334
}
3435

36+
// NewBufferflowTimed will create a new timed bufferflow
3537
func NewBufferflowTimed(port string, output chan<- []byte) *BufferflowTimed {
3638
return &BufferflowTimed{
3739
port: port,
@@ -44,6 +46,7 @@ func NewBufferflowTimed(port string, output chan<- []byte) *BufferflowTimed {
4446
}
4547
}
4648

49+
// Init will initialize the bufferflow
4750
func (b *BufferflowTimed) Init() {
4851
log.Println("Initting timed buffer flow (output once every 16ms)")
4952
go b.consumeInput()
@@ -72,10 +75,12 @@ Loop:
7275
close(b.input)
7376
}
7477

78+
// OnIncomingData will forward the data
7579
func (b *BufferflowTimed) OnIncomingData(data string) {
7680
b.input <- data
7781
}
7882

83+
// Close will close the bufferflow
7984
func (b *BufferflowTimed) Close() {
8085
b.ticker.Stop()
8186
b.done <- true

bufferflow_timedraw.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
log "github.com/sirupsen/logrus"
2323
)
2424

25+
// BufferflowTimedRaw sends raw data once every 16ms
2526
type BufferflowTimedRaw struct {
2627
port string
2728
output chan<- []byte
@@ -32,6 +33,7 @@ type BufferflowTimedRaw struct {
3233
sPortRaw string
3334
}
3435

36+
// NewBufferflowTimedRaw will create a new raw bufferflow
3537
func NewBufferflowTimedRaw(port string, output chan<- []byte) *BufferflowTimedRaw {
3638
return &BufferflowTimedRaw{
3739
port: port,
@@ -44,6 +46,7 @@ func NewBufferflowTimedRaw(port string, output chan<- []byte) *BufferflowTimedRa
4446
}
4547
}
4648

49+
// Init will initialize the bufferflow
4750
func (b *BufferflowTimedRaw) Init() {
4851
log.Println("Initting timed buffer raw flow (output once every 16ms)")
4952
go b.consumeInput()
@@ -73,10 +76,12 @@ Loop:
7376
close(b.input)
7477
}
7578

79+
// OnIncomingData will forward the data
7680
func (b *BufferflowTimedRaw) OnIncomingData(data string) {
7781
b.input <- data
7882
}
7983

84+
// Close will close the bufferflow
8085
func (b *BufferflowTimedRaw) Close() {
8186
b.ticker.Stop()
8287
b.done <- true

certificates.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func generateKey(ecdsaCurve string) (interface{}, error) {
7575
case "P521":
7676
return ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
7777
default:
78-
return nil, fmt.Errorf("Unrecognized elliptic curve: %q", ecdsaCurve)
78+
return nil, fmt.Errorf("unrecognized elliptic curve: %q", ecdsaCurve)
7979
}
8080
}
8181

@@ -87,7 +87,7 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
8787
} else {
8888
notBefore, err = time.Parse("Jan 2 15:04:05 2006", validFrom)
8989
if err != nil {
90-
return nil, fmt.Errorf("Failed to parse creation date: %s\n", err.Error())
90+
return nil, fmt.Errorf("failed to parse creation date: %s", err.Error())
9191
}
9292
}
9393

@@ -96,7 +96,7 @@ func generateSingleCertificate(isCa bool) (*x509.Certificate, error) {
9696
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
9797
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
9898
if err != nil {
99-
return nil, fmt.Errorf("failed to generate serial number: %s\n", err.Error())
99+
return nil, fmt.Errorf("failed to generate serial number: %s", err.Error())
100100
}
101101

102102
template := x509.Certificate{
@@ -164,7 +164,7 @@ func generateCertificates() {
164164
os.Exit(1)
165165
}
166166

167-
derBytes, err := x509.CreateCertificate(rand.Reader, caTemplate, caTemplate, publicKey(caKey), caKey)
167+
derBytes, _ := x509.CreateCertificate(rand.Reader, caTemplate, caTemplate, publicKey(caKey), caKey)
168168

169169
certOut, err := os.Create("ca.cert.pem")
170170
if err != nil {
@@ -202,7 +202,7 @@ func generateCertificates() {
202202
os.Exit(1)
203203
}
204204

205-
derBytes, err = x509.CreateCertificate(rand.Reader, template, caTemplate, publicKey(key), caKey)
205+
derBytes, _ = x509.CreateCertificate(rand.Reader, template, caTemplate, publicKey(key), caKey)
206206

207207
certOut, err = os.Create("cert.pem")
208208
if err != nil {
@@ -233,6 +233,7 @@ func deleteCertHandler(c *gin.Context) {
233233
DeleteCertificates()
234234
}
235235

236+
// DeleteCertificates will delete the certificates
236237
func DeleteCertificates() {
237238
os.Remove("ca.cert.pem")
238239
os.Remove("ca.cert.cer")

conn.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type connection struct {
4545
ws socketio.Socket
4646

4747
// Buffered channel of outbound messages.
48-
send chan []byte
49-
incoming chan []byte
48+
send chan []byte
5049
}
5150

5251
func (c *connection) writer() {
@@ -67,7 +66,7 @@ func (s *WsServer) ServeHTTP(c *gin.Context) {
6766
s.Server.ServeHTTP(c.Writer, c.Request)
6867
}
6968

70-
type AdditionalFile struct {
69+
type additionalFile struct {
7170
Hex []byte `json:"hex"`
7271
Filename string `json:"filename"`
7372
}
@@ -82,7 +81,7 @@ type Upload struct {
8281
Extra upload.Extra `json:"extra"`
8382
Hex []byte `json:"hex"`
8483
Filename string `json:"filename"`
85-
ExtraFiles []AdditionalFile `json:"extrafiles"`
84+
ExtraFiles []additionalFile `json:"extrafiles"`
8685
}
8786

8887
var uploadStatusStr = "ProgrammerStatus"
@@ -105,7 +104,7 @@ func uploadHandler(c *gin.Context) {
105104
return
106105
}
107106

108-
if data.Extra.Network == false {
107+
if !data.Extra.Network {
109108
if data.Signature == "" {
110109
c.String(http.StatusBadRequest, "signature is required")
111110
return

discovery.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func getPorts() ([]OsSerialPort, error) {
128128
for e := range results {
129129
log.Printf("%+v", e)
130130
if e.AddrIPv4 != nil {
131-
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), IdProduct: e.Instance, IdVendor: strings.Join(e.Text[:], " "), NetworkPort: true})
131+
arrPorts = append(arrPorts, OsSerialPort{Name: e.AddrIPv4.String(), IDProduct: e.Instance, IDVendor: strings.Join(e.Text[:], " "), NetworkPort: true})
132132
}
133133
}
134134
timeout <- true
@@ -140,10 +140,8 @@ func getPorts() ([]OsSerialPort, error) {
140140
return nil, err
141141
}
142142
// wait for some kind of timeout and return arrPorts
143-
select {
144-
case <-timeout:
145-
return arrPorts, nil
146-
}
143+
<-timeout
144+
return arrPorts, nil
147145
}
148146

149147
// Filter returns a new slice containing all OsSerialPort in the slice that satisfy the predicate f.

hub.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func checkCmd(m []byte) {
123123

124124
sl := strings.ToLower(strings.Trim(s, "\n"))
125125

126-
if *hibernate == true {
126+
if *hibernate {
127127
//do nothing
128128
return
129129
}
@@ -246,12 +246,12 @@ func checkCmd(m []byte) {
246246
func logAction(sl string) {
247247
if strings.HasPrefix(sl, "log on") {
248248
*logDump = "on"
249-
multi_writer := io.MultiWriter(&logger_ws, os.Stderr)
250-
log.SetOutput(multi_writer)
249+
multiWriter := io.MultiWriter(&loggerWs, os.Stderr)
250+
log.SetOutput(multiWriter)
251251
} else if strings.HasPrefix(sl, "log off") {
252252
*logDump = "off"
253253
log.SetOutput(os.Stderr)
254-
} else if strings.HasPrefix(sl, "log show") {
254+
// } else if strings.HasPrefix(sl, "log show") {
255255
// TODO: send all the saved log to websocket
256256
//h.broadcastSys <- []byte("{\"BufFlowDebug\" : \"" + *logDump + "\"}")
257257
}

0 commit comments

Comments
 (0)