Skip to content

Commit b6271c3

Browse files
committed
chore: start linting in CI
1 parent d3a2bb7 commit b6271c3

File tree

7 files changed

+60
-30
lines changed

7 files changed

+60
-30
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.25'
21+
check-latest: true
22+
23+
- name: Cache Go modules
24+
uses: actions/cache@v4
25+
with:
26+
path: |
27+
~/.cache/go-build
28+
~/go/pkg/mod
29+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
30+
restore-keys: |
31+
${{ runner.os }}-go-
32+
33+
- name: Download and verify dependencies
34+
run: make deps
35+
36+
- name: Run linting
37+
run: make lint
38+
1039
test:
1140
name: Test
1241
strategy:

boundary

-14.1 MB
Binary file not shown.

cmd/boundary/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
// Version information injected at build time
1111
var (
12+
//nolint:unused
1213
version = "dev" // Set via -ldflags "-X main.version=v1.0.0"
1314
)
1415

jail/macos.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (n *MacOSJail) setupPFRules() error {
272272

273273
// Enable PF if not already enabled
274274
cmd = exec.Command("pfctl", "-E")
275-
cmd.Run() // Ignore error as PF might already be enabled
275+
_ = cmd.Run() // Ignore error as PF might already be enabled
276276

277277
// Create and load main ruleset that includes our anchor
278278
mainRules := fmt.Sprintf(`# Temporary main ruleset to include boundary anchor
@@ -318,17 +318,17 @@ anchor "%s"
318318
func (n *MacOSJail) removePFRules() error {
319319
// Flush the anchor
320320
cmd := exec.Command("pfctl", "-a", pfAnchorName, "-F", "all")
321-
cmd.Run() // Ignore errors during cleanup
321+
_ = cmd.Run() // Ignore errors during cleanup
322322

323323
return nil
324324
}
325325

326326
// cleanupTempFiles removes temporary rule files
327327
func (n *MacOSJail) cleanupTempFiles() {
328328
if n.pfRulesPath != "" {
329-
os.Remove(n.pfRulesPath)
329+
_ = os.Remove(n.pfRulesPath)
330330
}
331331
if n.mainRulesPath != "" {
332-
os.Remove(n.mainRulesPath)
332+
_ = os.Remove(n.mainRulesPath)
333333
}
334334
}

proxy/proxy.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (p *Server) Start(ctx context.Context) error {
7171
if err != nil {
7272
select {
7373
case <-ctx.Done():
74-
listener.Close()
74+
_ = listener.Close()
7575
return
7676
default:
7777
p.logger.Error("Failed to accept connection", "error", err)
@@ -194,7 +194,7 @@ func (p *Server) forwardRequest(w http.ResponseWriter, r *http.Request, https bo
194194
http.Error(w, fmt.Sprintf("Failed to make request: %v", err), http.StatusBadGateway)
195195
return
196196
}
197-
defer resp.Body.Close()
197+
defer func() { _ = resp.Body.Close() }()
198198

199199
p.logger.Debug("Received response", "status", resp.StatusCode, "target", targetURL.String())
200200

@@ -238,7 +238,7 @@ func (p *Server) writeBlockedResponse(w http.ResponseWriter, r *http.Request) {
238238
host = r.Host
239239
}
240240

241-
fmt.Fprintf(w, `🚫 Request Blocked by Boundary
241+
_, _ = fmt.Fprintf(w, `🚫 Request Blocked by Boundary
242242
243243
Request: %s %s
244244
Host: %s
@@ -290,7 +290,7 @@ func (p *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
290290
p.logger.Error("Failed to hijack connection", "error", err)
291291
return
292292
}
293-
defer conn.Close()
293+
defer func() { _ = conn.Close() }()
294294

295295
// Send 200 Connection established response manually
296296
_, err = conn.Write([]byte("HTTP/1.1 200 Connection established\r\n\r\n"))
@@ -416,7 +416,7 @@ func (p *Server) handleDecryptedHTTPS(w http.ResponseWriter, r *http.Request) {
416416

417417
// handleConnectionWithTLSDetection detects TLS vs HTTP and handles appropriately
418418
func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
419-
defer conn.Close()
419+
defer func() { _ = conn.Close() }()
420420

421421
// Peek at first byte to detect protocol
422422
buf := make([]byte, 1)
@@ -442,15 +442,15 @@ func (p *Server) handleConnectionWithTLSDetection(conn net.Conn) {
442442
p.logger.Debug("TLS handshake successful")
443443
// Use HTTP server with TLS connection
444444
listener := newSingleConnectionListener(tlsConn)
445-
defer listener.Close()
445+
defer func() { _ = listener.Close() }()
446446
err = http.Serve(listener, http.HandlerFunc(p.handleDecryptedHTTPS))
447447
p.logger.Debug("http.Serve completed for HTTPS", "error", err)
448448
} else {
449449
p.logger.Debug("Detected HTTP request, handling normally")
450450
// Use HTTP server with regular connection
451451
p.logger.Debug("About to call http.Serve for HTTP connection")
452452
listener := newSingleConnectionListener(connWrapper)
453-
defer listener.Close()
453+
defer func() { _ = listener.Close() }()
454454
err = http.Serve(listener, http.HandlerFunc(p.handleHTTP))
455455
p.logger.Debug("http.Serve completed", "error", err)
456456
}
@@ -519,7 +519,7 @@ func (sl *singleConnectionListener) Close() error {
519519
}
520520

521521
if sl.conn != nil {
522-
sl.conn.Close()
522+
_ = sl.conn.Close()
523523
sl.conn = nil
524524
}
525525
return nil
@@ -613,9 +613,9 @@ func (p *Server) constructFullURL(req *http.Request, hostname string) string {
613613

614614
// writeBlockedResponseStreaming writes a blocked response directly to the TLS connection
615615
func (p *Server) writeBlockedResponseStreaming(tlsConn *tls.Conn, req *http.Request) {
616-
response := fmt.Sprintf("HTTP/1.1 403 Forbidden\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n🚫 Request Blocked by Boundary\n\nRequest: %s %s\nHost: %s\n\nTo allow this request, restart boundary with:\n --allow \"%s\"\n",
616+
response := fmt.Sprintf("HTTP/1.1 403 Forbidden\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n🚫 Request Blocked by Boundary\n\nRequest: %s %s\nHost: %s\n\nTo allow this request, restart boundary with:\n --allow \"%s\"\n",
617617
req.Method, req.URL.Path, req.Host, req.Host)
618-
tlsConn.Write([]byte(response))
618+
_, _ = tlsConn.Write([]byte(response))
619619
}
620620

621621
// streamRequestToTarget streams the HTTP request (including body) to the target server
@@ -625,29 +625,29 @@ func (p *Server) streamRequestToTarget(clientConn *tls.Conn, bufReader *bufio.Re
625625
if err != nil {
626626
return fmt.Errorf("failed to connect to target %s: %v", hostname, err)
627627
}
628-
defer targetConn.Close()
628+
defer func() { _ = targetConn.Close() }()
629629

630630
// Send HTTP request headers to target
631631
reqLine := fmt.Sprintf("%s %s %s\r\n", req.Method, req.URL.RequestURI(), req.Proto)
632-
targetConn.Write([]byte(reqLine))
632+
_, _ = targetConn.Write([]byte(reqLine))
633633

634634
// Send headers
635635
for name, values := range req.Header {
636636
for _, value := range values {
637637
headerLine := fmt.Sprintf("%s: %s\r\n", name, value)
638-
targetConn.Write([]byte(headerLine))
638+
_, _ = targetConn.Write([]byte(headerLine))
639639
}
640640
}
641-
targetConn.Write([]byte("\r\n")) // End of headers
641+
_, _ = targetConn.Write([]byte("\r\n")) // End of headers
642642

643643
// Stream request body and response bidirectionally
644644
go func() {
645645
// Stream request body: client -> target
646-
io.Copy(targetConn, bufReader)
646+
_, _ = io.Copy(targetConn, bufReader)
647647
}()
648648

649649
// Stream response: target -> client
650-
io.Copy(clientConn, targetConn)
650+
_, _ = io.Copy(clientConn, targetConn)
651651
return nil
652652
}
653653

@@ -661,7 +661,7 @@ func (p *Server) handleConnectStreaming(tlsConn *tls.Conn, req *http.Request, ho
661661

662662
// Send CONNECT response
663663
response := "HTTP/1.1 200 Connection established\r\n\r\n"
664-
tlsConn.Write([]byte(response))
664+
_, _ = tlsConn.Write([]byte(response))
665665

666666
// Now the client will try to do TLS handshake for the target server
667667
// But we want to intercept and terminate it
@@ -676,9 +676,9 @@ func (p *Server) handleConnectStreaming(tlsConn *tls.Conn, req *http.Request, ho
676676
p.logger.Error("Failed to connect to CONNECT target", "target", req.Host, "error", err)
677677
return
678678
}
679-
defer targetConn.Close()
680-
679+
defer func() { _ = targetConn.Close() }()
680+
681681
// Bidirectional copy
682-
go io.Copy(targetConn, tlsConn)
683-
io.Copy(tlsConn, targetConn)
682+
go func() { _, _ = io.Copy(targetConn, tlsConn) }()
683+
_, _ = io.Copy(tlsConn, targetConn)
684684
}

rules/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func newAllowRule(spec string) (Rule, error) {
185185
right := strings.TrimSpace(s[idx:])
186186
// methods part is valid if it only contains letters and commas
187187
valid := left != "" && strings.IndexFunc(left, func(r rune) bool {
188-
return !(r == ',' || (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z'))
188+
return r != ',' && (r < 'A' || r > 'Z') && (r < 'a' || r > 'z')
189189
}) == -1
190190
if valid {
191191
methods = make(map[string]bool)

tls/tls.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ func (cm *CertificateManager) generateCA(keyPath, certPath string) error {
229229
if err != nil {
230230
return fmt.Errorf("failed to create key file: %v", err)
231231
}
232-
defer keyFile.Close()
232+
defer func() { _ = keyFile.Close() }()
233233

234-
pem.Encode(keyFile, &pem.Block{
234+
_ = pem.Encode(keyFile, &pem.Block{
235235
Type: "RSA PRIVATE KEY",
236236
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
237237
})
@@ -241,9 +241,9 @@ func (cm *CertificateManager) generateCA(keyPath, certPath string) error {
241241
if err != nil {
242242
return fmt.Errorf("failed to create cert file: %v", err)
243243
}
244-
defer certFile.Close()
244+
defer func() { _ = certFile.Close() }()
245245

246-
pem.Encode(certFile, &pem.Block{
246+
_ = pem.Encode(certFile, &pem.Block{
247247
Type: "CERTIFICATE",
248248
Bytes: certDER,
249249
})

0 commit comments

Comments
 (0)