func (l *Locker) Unlock() {
	if fd := l.fd; fd != invalidFileHandle {
		syscall.CloseHandle(fd)
	}
}
Unlock file resource.
package setlock
import (
	"fmt"
	"sync"
	"syscall"
	"unsafe"
)
const (
	invalidFileHandle      = ^syscall.Handle(0)
	lockfileExclusiveLock  = 0x0002
	lockfileFailImmediatly = 0x0001
)
var (
	modkernel32    = syscall.NewLazyDLL("kernel32.dll")
	procLockFileEx = modkernel32.NewProc("LockFileEx")
)
type Locker struct {
	nonblock bool
	filename string
	fd       syscall.Handle
}
func NewLocker(filename string, nonblock bool) *Locker {
	return &Locker{
		nonblock: nonblock,
		filename: filename,
		fd:       invalidFileHandle,
	}
}
func (l *Locker) Lock() {
	if err := l.LockWithErr(); err != nil {
		panic(err)
	}
}
func (l *Locker) LockWithErr() error {
	if l.fd != invalidFileHandle {
		return ErrFailedToAcquireLock
	}
	var flags uint32
	if l.nonblock {
		flags = lockfileExclusiveLock | lockfileFailImmediatly
	} else {
		flags = lockfileExclusiveLock
	}
	if l.filename == "" {
		return ErrLockFileEmpty
	}
	fd, err := syscall.CreateFile(&(syscall.StringToUTF16(l.filename)[0]), syscall.GENERIC_READ|syscall.GENERIC_WRITE,
		syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE, nil, syscall.OPEN_ALWAYS, syscall.FILE_ATTRIBUTE_NORMAL, 0)
	if err != nil {
		return fmt.Errorf("setlock: fatal: unable to open %s: temporary failure", l.filename)
	}
	if fd == invalidFileHandle {
		return ErrFailedToAcquireLock
	}
	defer func() {
		if l.fd == invalidFileHandle {
			syscall.CloseHandle(fd)
		}
	}()
	var ol syscall.Overlapped
	var mu sync.RWMutex
	mu.Lock()
	defer mu.Unlock()
	r1, _, _ := syscall.Syscall6(
		procLockFileEx.Addr(),
		6,
		uintptr(fd),  
		uintptr(flags),
		uintptr(0),  
		uintptr(1),  
		uintptr(0),  
		uintptr(unsafe.Pointer(&ol)),
	)
	if r1 == 0 {
		return ErrFailedToAcquireLock
	}
	l.fd = fd
	return nil
}