Skip to content

Commit 182247f

Browse files
committed
global: apply gofumpt
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 32b3cb6 commit 182247f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+140
-125
lines changed

conf/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ type Endpoint struct {
2727
Port uint16
2828
}
2929

30-
type Key [KeyLength]byte
31-
type HandshakeTime time.Duration
32-
type Bytes uint64
30+
type (
31+
Key [KeyLength]byte
32+
HandshakeTime time.Duration
33+
Bytes uint64
34+
)
3335

3436
type Config struct {
3537
Name string

conf/migration_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"golang.org/x/sys/windows"
1919
)
2020

21-
var migrating sync.Mutex
22-
var lastMigrationTimer *time.Timer
21+
var (
22+
migrating sync.Mutex
23+
lastMigrationTimer *time.Timer
24+
)
2325

2426
type MigrationCallback func(name, oldPath, newPath string)
2527

@@ -53,7 +55,7 @@ func migrateUnencryptedConfigs(sharingBase int, migrated MigrationCallback) {
5355
if err != nil {
5456
continue
5557
}
56-
if info.Mode().Perm()&0444 == 0 {
58+
if info.Mode().Perm()&0o444 == 0 {
5759
continue
5860
}
5961

conf/name.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ var reservedNames = []string{
1818
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
1919
}
2020

21-
const serviceNameForbidden = "$"
22-
const netshellDllForbidden = "\\/:*?\"<>|\t"
23-
const specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00"
21+
const (
22+
serviceNameForbidden = "$"
23+
netshellDllForbidden = "\\/:*?\"<>|\t"
24+
specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00"
25+
)
2426

2527
var allowedNameFormat = regexp.MustCompile("^[a-zA-Z0-9_=+.-]{1,32}$")
2628

@@ -60,6 +62,7 @@ type naturalSortToken struct {
6062
maybeString string
6163
maybeNumber int
6264
}
65+
6366
type naturalSortString struct {
6467
originalString string
6568
tokens []naturalSortToken

conf/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (c *Config) maybeAddPeer(p *Peer) {
158158
}
159159
}
160160

161-
func FromWgQuick(s string, name string) (*Config, error) {
161+
func FromWgQuick(s, name string) (*Config, error) {
162162
if !TunnelNameIsValid(name) {
163163
return nil, &ParseError{l18n.Sprintf("Tunnel name is not valid"), name}
164164
}
@@ -319,7 +319,7 @@ func FromWgQuick(s string, name string) (*Config, error) {
319319
return &conf, nil
320320
}
321321

322-
func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) {
322+
func FromWgQuickWithUnknownEncoding(s, name string) (*Config, error) {
323323
c, firstErr := FromWgQuick(s, name)
324324
if firstErr == nil {
325325
return c, nil

conf/parser_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func equal(t *testing.T, expected, actual interface{}) bool {
5454
t.Errorf("Failed equals at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected)
5555
return false
5656
}
57+
5758
func lenTest(t *testing.T, actualO interface{}, expected int) bool {
5859
actual := reflect.ValueOf(actualO).Len()
5960
if reflect.DeepEqual(expected, actual) {
@@ -63,6 +64,7 @@ func lenTest(t *testing.T, actualO interface{}, expected int) bool {
6364
t.Errorf("Wrong length at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected)
6465
return false
6566
}
67+
6668
func contains(t *testing.T, list, element interface{}) bool {
6769
listValue := reflect.ValueOf(list)
6870
for i := 0; i < listValue.Len(); i++ {

conf/path_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import (
1515
"golang.org/x/sys/windows"
1616
)
1717

18-
var cachedConfigFileDir string
19-
var cachedRootDir string
18+
var (
19+
cachedConfigFileDir string
20+
cachedRootDir string
21+
)
2022

2123
func tunnelConfigurationsDirectory() (string, error) {
2224
if cachedConfigFileDir != "" {
@@ -27,7 +29,7 @@ func tunnelConfigurationsDirectory() (string, error) {
2729
return "", err
2830
}
2931
c := filepath.Join(root, "Configurations")
30-
err = os.Mkdir(c, os.ModeDir|0700)
32+
err = os.Mkdir(c, os.ModeDir|0o700)
3133
if err != nil && !os.IsExist(err) {
3234
return "", err
3335
}

conf/store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
"golang.zx2c4.com/wireguard/windows/conf/dpapi"
1515
)
1616

17-
const configFileSuffix = ".conf.dpapi"
18-
const configFileUnencryptedSuffix = ".conf"
17+
const (
18+
configFileSuffix = ".conf.dpapi"
19+
configFileUnencryptedSuffix = ".conf"
20+
)
1921

2022
func ListConfigNames() ([]string, error) {
2123
configFileDir, err := tunnelConfigurationsDirectory()
@@ -40,7 +42,7 @@ func ListConfigNames() ([]string, error) {
4042
if err != nil {
4143
continue
4244
}
43-
if info.Mode().Perm()&0444 == 0 {
45+
if info.Mode().Perm()&0o444 == 0 {
4446
continue
4547
}
4648
configs[i] = name

driver/driver_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func closeAdapter(wireguard *Adapter) {
7979
// the GUID of the created network adapter, which then influences NLA generation
8080
// deterministically. If it is set to nil, the GUID is chosen by the system at random,
8181
// and hence a new NLA entry is created for each new adapter.
82-
func CreateAdapter(name string, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) {
82+
func CreateAdapter(name, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) {
8383
var name16 *uint16
8484
name16, err = windows.UTF16PtrFromString(name)
8585
if err != nil {

driver/memmod/memmod_windows.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (module *Module) headerDirectory(idx int) *IMAGE_DATA_DIRECTORY {
4747
return &module.headers.OptionalHeader.DataDirectory[idx]
4848
}
4949

50-
func (module *Module) copySections(address uintptr, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error {
50+
func (module *Module) copySections(address, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error {
5151
sections := module.headers.Sections()
5252
for i := range sections {
5353
if sections[i].SizeOfRawData == 0 {
@@ -139,7 +139,7 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
139139
}
140140

141141
// determine protection flags based on characteristics
142-
var ProtectionFlags = [8]uint32{
142+
ProtectionFlags := [8]uint32{
143143
windows.PAGE_NOACCESS, // not writeable, not readable, not executable
144144
windows.PAGE_EXECUTE, // not writeable, not readable, executable
145145
windows.PAGE_READONLY, // not writeable, readable, not executable
@@ -387,10 +387,12 @@ type addressRange struct {
387387
end uintptr
388388
}
389389

390-
var loadedAddressRanges []addressRange
391-
var loadedAddressRangesMu sync.RWMutex
392-
var haveHookedRtlPcToFileHeader sync.Once
393-
var hookRtlPcToFileHeaderResult error
390+
var (
391+
loadedAddressRanges []addressRange
392+
loadedAddressRangesMu sync.RWMutex
393+
haveHookedRtlPcToFileHeader sync.Once
394+
hookRtlPcToFileHeaderResult error
395+
)
394396

395397
func hookRtlPcToFileHeader() error {
396398
var kernelBase windows.Handle

driver/wintunremoval_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func UninstallLegacyWintun() error {
15-
var deviceClassNetGUID = &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
15+
deviceClassNetGUID := &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
1616
devInfo, err := windows.SetupDiCreateDeviceInfoListEx(deviceClassNetGUID, 0, "")
1717
if err != nil {
1818
return err

elevate/shellexecute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
cSEE_MASK_DEFAULT = 0
2525
)
2626

27-
func ShellExecute(program string, arguments string, directory string, show int32) (err error) {
27+
func ShellExecute(program, arguments, directory string, show int32) (err error) {
2828
var (
2929
program16 *uint16
3030
arguments16 *uint16

embeddable-dll-service/main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ package main
77

88
import (
99
"C"
10+
"crypto/rand"
11+
"log"
12+
"path/filepath"
13+
"unsafe"
1014

1115
"golang.org/x/crypto/curve25519"
1216
"golang.org/x/sys/windows"
1317

1418
"golang.zx2c4.com/wireguard/windows/conf"
1519
"golang.zx2c4.com/wireguard/windows/tunnel"
16-
17-
"crypto/rand"
18-
"log"
19-
"path/filepath"
20-
"unsafe"
2120
)
2221

2322
//export WireGuardTunnelService
@@ -33,7 +32,7 @@ func WireGuardTunnelService(confFile16 *uint16) bool {
3332
}
3433

3534
//export WireGuardGenerateKeypair
36-
func WireGuardGenerateKeypair(publicKey *byte, privateKey *byte) {
35+
func WireGuardGenerateKeypair(publicKey, privateKey *byte) {
3736
publicKeyArray := (*[32]byte)(unsafe.Pointer(publicKey))
3837
privateKeyArray := (*[32]byte)(unsafe.Pointer(privateKey))
3938
n, err := rand.Read(privateKeyArray[:])

l18n/l18n.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
"golang.org/x/text/message"
1414
)
1515

16-
var printer *message.Printer
17-
var printerLock sync.Mutex
16+
var (
17+
printer *message.Printer
18+
printerLock sync.Mutex
19+
)
1820

1921
// prn returns the printer for user preferred UI language.
2022
func prn() *message.Printer {

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func fatalf(format string, v ...interface{}) {
5454
fatal(l18n.Sprintf(format, v...))
5555
}
5656

57-
func info(title string, format string, v ...interface{}) {
57+
func info(title, format string, v ...interface{}) {
5858
if log.Writer() == io.Discard {
5959
windows.MessageBox(0, windows.StringToUTF16Ptr(l18n.Sprintf(format, v...)), windows.StringToUTF16Ptr(title), windows.MB_ICONINFORMATION)
6060
} else {
@@ -63,7 +63,7 @@ func info(title string, format string, v ...interface{}) {
6363
}
6464

6565
func usage() {
66-
var flags = [...]string{
66+
flags := [...]string{
6767
l18n.Sprintf("(no argument): elevate and install manager service"),
6868
"/installmanagerservice",
6969
"/installtunnelservice CONFIG_PATH",

manager/ipc_client.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var (
6464
)
6565

6666
type TunnelChangeCallback struct {
67-
cb func(tunnel *Tunnel, state TunnelState, globalState TunnelState, err error)
67+
cb func(tunnel *Tunnel, state, globalState TunnelState, err error)
6868
}
6969

7070
var tunnelChangeCallbacks = make(map[*TunnelChangeCallback]bool)
@@ -93,7 +93,7 @@ type UpdateProgressCallback struct {
9393

9494
var updateProgressCallbacks = make(map[*UpdateProgressCallback]bool)
9595

96-
func InitializeIPCClient(reader *os.File, writer *os.File, events *os.File) {
96+
func InitializeIPCClient(reader, writer, events *os.File) {
9797
rpcDecoder = gob.NewDecoder(reader)
9898
rpcEncoder = gob.NewEncoder(writer)
9999
go func() {
@@ -431,43 +431,52 @@ func IPCClientUpdate() error {
431431
return rpcEncoder.Encode(UpdateMethodType)
432432
}
433433

434-
func IPCClientRegisterTunnelChange(cb func(tunnel *Tunnel, state TunnelState, globalState TunnelState, err error)) *TunnelChangeCallback {
434+
func IPCClientRegisterTunnelChange(cb func(tunnel *Tunnel, state, globalState TunnelState, err error)) *TunnelChangeCallback {
435435
s := &TunnelChangeCallback{cb}
436436
tunnelChangeCallbacks[s] = true
437437
return s
438438
}
439+
439440
func (cb *TunnelChangeCallback) Unregister() {
440441
delete(tunnelChangeCallbacks, cb)
441442
}
443+
442444
func IPCClientRegisterTunnelsChange(cb func()) *TunnelsChangeCallback {
443445
s := &TunnelsChangeCallback{cb}
444446
tunnelsChangeCallbacks[s] = true
445447
return s
446448
}
449+
447450
func (cb *TunnelsChangeCallback) Unregister() {
448451
delete(tunnelsChangeCallbacks, cb)
449452
}
453+
450454
func IPCClientRegisterManagerStopping(cb func()) *ManagerStoppingCallback {
451455
s := &ManagerStoppingCallback{cb}
452456
managerStoppingCallbacks[s] = true
453457
return s
454458
}
459+
455460
func (cb *ManagerStoppingCallback) Unregister() {
456461
delete(managerStoppingCallbacks, cb)
457462
}
463+
458464
func IPCClientRegisterUpdateFound(cb func(updateState UpdateState)) *UpdateFoundCallback {
459465
s := &UpdateFoundCallback{cb}
460466
updateFoundCallbacks[s] = true
461467
return s
462468
}
469+
463470
func (cb *UpdateFoundCallback) Unregister() {
464471
delete(updateFoundCallbacks, cb)
465472
}
473+
466474
func IPCClientRegisterUpdateProgress(cb func(dp updater.DownloadProgress)) *UpdateProgressCallback {
467475
s := &UpdateProgressCallback{cb}
468476
updateProgressCallbacks[s] = true
469477
return s
470478
}
479+
471480
func (cb *UpdateProgressCallback) Unregister() {
472481
delete(updateProgressCallbacks, cb)
473482
}

manager/ipc_driver.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ type lockedDriverAdapter struct {
1616
sync.Mutex
1717
}
1818

19-
var driverAdapters = make(map[string]*lockedDriverAdapter)
20-
var driverAdaptersLock sync.RWMutex
19+
var (
20+
driverAdapters = make(map[string]*lockedDriverAdapter)
21+
driverAdaptersLock sync.RWMutex
22+
)
2123

2224
func findDriverAdapter(tunnelName string) (*lockedDriverAdapter, error) {
2325
driverAdaptersLock.RLock()

manager/ipc_server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import (
2323
"golang.zx2c4.com/wireguard/windows/updater"
2424
)
2525

26-
var managerServices = make(map[*ManagerService]bool)
27-
var managerServicesLock sync.RWMutex
28-
var haveQuit uint32
29-
var quitManagersChan = make(chan struct{}, 1)
26+
var (
27+
managerServices = make(map[*ManagerService]bool)
28+
managerServicesLock sync.RWMutex
29+
haveQuit uint32
30+
quitManagersChan = make(chan struct{}, 1)
31+
)
3032

3133
type ManagerService struct {
3234
events *os.File
@@ -439,7 +441,7 @@ func (s *ManagerService) ServeConn(reader io.Reader, writer io.Writer) {
439441
}
440442
}
441443

442-
func IPCServerListen(reader *os.File, writer *os.File, events *os.File, elevatedToken windows.Token) {
444+
func IPCServerListen(reader, writer, events *os.File, elevatedToken windows.Token) {
443445
service := &ManagerService{
444446
events: events,
445447
elevatedToken: elevatedToken,

manager/service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
207207
windows.Handle(theirReader.Fd()),
208208
windows.Handle(theirWriter.Fd()),
209209
windows.Handle(theirEvents.Fd()),
210-
theirLogMapping}, runToken)
210+
theirLogMapping,
211+
}, runToken)
211212
} else {
212213
err = errors.New("Session has logged out")
213214
}

manager/tunneltracker.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"golang.zx2c4.com/wireguard/windows/services"
2525
)
2626

27-
var trackedTunnels = make(map[string]TunnelState)
28-
var trackedTunnelsLock = sync.Mutex{}
27+
var (
28+
trackedTunnels = make(map[string]TunnelState)
29+
trackedTunnelsLock = sync.Mutex{}
30+
)
2931

3032
func trackedTunnelsGlobalState() (state TunnelState) {
3133
state = TunnelStopped

0 commit comments

Comments
 (0)