mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
Fix staticcheck linter warnings
By moving darwin specific codes to darwin file.
This commit is contained in:
committed by
Cuong Manh Le
parent
8bd3b9e474
commit
54cb455522
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -244,3 +245,38 @@ func getAllDHCPNameservers() []string {
|
|||||||
|
|
||||||
return allNameservers
|
return allNameservers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func patchNetIfaceName(iface *net.Interface) (bool, error) {
|
||||||
|
b, err := exec.Command("networksetup", "-listnetworkserviceorder").Output()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
patched := false
|
||||||
|
if name := networkServiceName(iface.Name, bytes.NewReader(b)); name != "" {
|
||||||
|
patched = true
|
||||||
|
iface.Name = name
|
||||||
|
}
|
||||||
|
return patched, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func networkServiceName(ifaceName string, r io.Reader) string {
|
||||||
|
scanner := bufio.NewScanner(r)
|
||||||
|
prevLine := ""
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
if strings.Contains(line, "*") {
|
||||||
|
// Network services is disabled.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !strings.Contains(line, "Device: "+ifaceName) {
|
||||||
|
prevLine = line
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts := strings.SplitN(prevLine, " ", 2)
|
||||||
|
if len(parts) == 2 {
|
||||||
|
return strings.TrimSpace(parts[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package ctrld
|
package ctrld
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -81,38 +77,3 @@ func SavedStaticNameservers(iface *net.Interface) ([]string, string) {
|
|||||||
}
|
}
|
||||||
return ns, file
|
return ns, file
|
||||||
}
|
}
|
||||||
|
|
||||||
func patchNetIfaceName(iface *net.Interface) (bool, error) {
|
|
||||||
b, err := exec.Command("networksetup", "-listnetworkserviceorder").Output()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
patched := false
|
|
||||||
if name := networkServiceName(iface.Name, bytes.NewReader(b)); name != "" {
|
|
||||||
patched = true
|
|
||||||
iface.Name = name
|
|
||||||
}
|
|
||||||
return patched, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkServiceName(ifaceName string, r io.Reader) string {
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
prevLine := ""
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Text()
|
|
||||||
if strings.Contains(line, "*") {
|
|
||||||
// Network services is disabled.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !strings.Contains(line, "Device: "+ifaceName) {
|
|
||||||
prevLine = line
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
parts := strings.SplitN(prevLine, " ", 2)
|
|
||||||
if len(parts) == 2 {
|
|
||||||
return strings.TrimSpace(parts[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user