Skip to content

Commit fa303f2

Browse files
Apply task go:lint suggestions
1 parent 42727eb commit fa303f2

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

Diff for: devicenotification/devicenotification.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ import (
4242
"golang.org/x/sys/windows"
4343
)
4444

45-
var osThreadId atomic.Uint32
45+
var osThreadID atomic.Uint32
4646

4747
// Start the device add/remove notification process, at every event a call to eventCB will be performed.
4848
// This function will block until interrupted by the given context. Errors will be passed to errorCB.
4949
// Returns error if sync process can't be started.
5050
func Start(ctx context.Context, eventCB func(), errorCB func(msg string)) error {
5151
runtime.LockOSThread()
5252
defer runtime.UnlockOSThread()
53-
osThreadId.Store(windows.GetCurrentThreadId())
53+
osThreadID.Store(windows.GetCurrentThreadId())
5454

5555
eventsChan := make(chan bool, 1)
5656
var eventsChanLock sync.Mutex
@@ -108,24 +108,24 @@ func Start(ctx context.Context, eventCB func(), errorCB func(msg string)) error
108108

109109
go func() {
110110
<-ctx.Done()
111-
_ = win32.PostMessage(windowHandle, win32.WM_Quit, 0, 0)
111+
_ = win32.PostMessage(windowHandle, win32.WMQuit, 0, 0)
112112
}()
113113

114114
for {
115115
// Verify running thread prerequisites
116-
if currThreadId := windows.GetCurrentThreadId(); currThreadId != osThreadId.Load() {
117-
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadId, osThreadId))
116+
if currThreadID := windows.GetCurrentThreadId(); currThreadID != osThreadID.Load() {
117+
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadID, osThreadID))
118118
}
119119

120120
var m win32.TagMSG
121-
if res := win32.GetMessage(&m, windowHandle, win32.WM_Quit, win32.WM_Quit); res == 0 { // 0 means we got a WM_QUIT
121+
if res := win32.GetMessage(&m, windowHandle, win32.WMQuit, win32.WMQuit); res == 0 { // 0 means we got a WMQUIT
122122
break
123123
} else if res == -1 { // -1 means that an error occurred
124124
err := windows.GetLastError()
125125
errorCB("error consuming messages: " + err.Error())
126126
break
127127
} else {
128-
// we got a message != WM_Quit, it should not happen but, just in case...
128+
// we got a message != WMQuit, it should not happen but, just in case...
129129
win32.TranslateMessage(&m)
130130
win32.DispatchMessage(&m)
131131
}
@@ -136,8 +136,8 @@ func Start(ctx context.Context, eventCB func(), errorCB func(msg string)) error
136136

137137
func createWindow(windowCallback win32.WindowProcCallback) (syscall.Handle, *byte, error) {
138138
// Verify running thread prerequisites
139-
if currThreadId := windows.GetCurrentThreadId(); currThreadId != osThreadId.Load() {
140-
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadId, osThreadId.Load()))
139+
if currThreadID := windows.GetCurrentThreadId(); currThreadID != osThreadID.Load() {
140+
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadID, osThreadID.Load()))
141141
}
142142

143143
moduleHandle, err := win32.GetModuleHandle(nil)
@@ -167,8 +167,8 @@ func createWindow(windowCallback win32.WindowProcCallback) (syscall.Handle, *byt
167167

168168
func destroyWindow(windowHandle syscall.Handle, className *byte) error {
169169
// Verify running thread prerequisites
170-
if currThreadId := windows.GetCurrentThreadId(); currThreadId != osThreadId.Load() {
171-
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadId, osThreadId.Load()))
170+
if currThreadID := windows.GetCurrentThreadId(); currThreadID != osThreadID.Load() {
171+
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadID, osThreadID.Load()))
172172
}
173173

174174
if err := win32.DestroyWindowEx(windowHandle); err != nil {
@@ -182,8 +182,8 @@ func destroyWindow(windowHandle syscall.Handle, className *byte) error {
182182

183183
func registerNotifications(windowHandle syscall.Handle) (syscall.Handle, error) {
184184
// Verify running thread prerequisites
185-
if currThreadId := windows.GetCurrentThreadId(); currThreadId != osThreadId.Load() {
186-
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadId, osThreadId.Load()))
185+
if currThreadID := windows.GetCurrentThreadId(); currThreadID != osThreadID.Load() {
186+
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadID, osThreadID.Load()))
187187
}
188188

189189
notificationFilter := win32.DevBroadcastDeviceInterface{
@@ -203,8 +203,8 @@ func registerNotifications(windowHandle syscall.Handle) (syscall.Handle, error)
203203

204204
func unregisterNotifications(notificationsDevHandle syscall.Handle) error {
205205
// Verify running thread prerequisites
206-
if currThreadId := windows.GetCurrentThreadId(); currThreadId != osThreadId.Load() {
207-
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadId, osThreadId.Load()))
206+
if currThreadID := windows.GetCurrentThreadId(); currThreadID != osThreadID.Load() {
207+
panic(fmt.Sprintf("this function must run on the main OS Thread: currThread=%d, osThread=%d", currThreadID, osThreadID.Load()))
208208
}
209209

210210
if err := win32.UnregisterDeviceNotification(notificationsDevHandle); err != nil {

Diff for: doc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
* the GNU General Public License.
2828
*/
2929

30-
// win32 is a collection of useful bindings to Win32 API that are not available in the standard
30+
// Package win32 is a collection of useful bindings to Win32 API that are not available in the standard
3131
// golang windows/syscall package.
3232
package win32

Diff for: syscall_windows.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ type TagMSG struct {
262262
LPrivate int32
263263
}
264264

265-
const WM_Quit = 0x0012
265+
const WMQuit = 0x0012
266266

267267
const WsExDlgModalFrame = 0x00000001
268268
const WsExTopmost = 0x00000008
@@ -272,7 +272,7 @@ const WsExToolWindow = 0x00000080
272272
const WsExAppWindow = 0x00040000
273273
const WsExLayered = 0x00080000
274274

275-
type Guid struct {
275+
type GUID struct {
276276
Data1 uint32
277277
Data2 uint16
278278
Data3 uint16
@@ -283,12 +283,12 @@ type DevBroadcastDeviceInterface struct {
283283
DwSize uint32
284284
DwDeviceType uint32
285285
DwReserved uint32
286-
ClassGUID Guid
286+
ClassGUID GUID
287287
SzName uint16
288288
}
289289

290-
// USB devices GUID used to filter notifications
291-
var UsbEventGUID Guid = Guid{
290+
// UsbEventGUID is USB devices GUID used to filter notifications
291+
var UsbEventGUID GUID = GUID{
292292
Data1: 0x10bfdca5,
293293
Data2: 0x3065,
294294
Data3: 0xd211,
@@ -301,8 +301,8 @@ const DeviceNotifyAllInterfaceClasses = 4
301301

302302
const DbtDevtypeDeviceInterface = 5
303303

304-
const PM_NoRemove = 0x0000
305-
const PM_Remove = 0x0001
306-
const PM_NoYield = 0x0002
304+
const PMNoRemove = 0x0000
305+
const PMRemove = 0x0001
306+
const PMNoYield = 0x0002
307307

308308
type WindowProcCallback func(hwnd syscall.Handle, msg uint32, wParam uintptr, lParam uintptr) uintptr

0 commit comments

Comments
 (0)