rename non-camel-case vars, refactor, satisfy linter

This commit is contained in:
2026-08-22 17:47:37 +02:00
parent 9e558e1f3c
commit d64f84c887
13 changed files with 220 additions and 206 deletions

16
net.go
View File

@@ -8,7 +8,7 @@ import (
"os"
)
// Contains a raw json response, not marshalled yet.
// RawResponse contains a raw json response, not marshalled yet.
type RawResponse struct {
PayloadType int
Payload []byte
@@ -39,14 +39,13 @@ func (ipc *SwayIPC) Close() error {
}
func (ipc *SwayIPC) sendHeader(messageType uint32, len uint32) error {
sendPayload := make([]byte, IPC_HEADER_SIZE)
sendPayload := make([]byte, IpcHeaderSize)
copy(sendPayload, []byte(IPC_MAGIC))
binary.LittleEndian.PutUint32(sendPayload[IPC_MAGIC_LEN:], len)
binary.LittleEndian.PutUint32(sendPayload[IPC_MAGIC_LEN+4:], messageType)
copy(sendPayload, []byte(IpcMagix))
binary.LittleEndian.PutUint32(sendPayload[IpcMagicLen:], len)
binary.LittleEndian.PutUint32(sendPayload[IpcMagicLen+4:], messageType)
_, err := ipc.socket.Write(sendPayload)
if err != nil {
return fmt.Errorf("failed to send header to IPC socket %w", err)
}
@@ -56,7 +55,6 @@ func (ipc *SwayIPC) sendHeader(messageType uint32, len uint32) error {
func (ipc *SwayIPC) sendPayload(payload []byte) error {
_, err := ipc.socket.Write(payload)
if err != nil {
return fmt.Errorf("failed to send payload to IPC socket %w", err)
}
@@ -66,14 +64,14 @@ func (ipc *SwayIPC) sendPayload(payload []byte) error {
func (ipc *SwayIPC) readResponse() (*RawResponse, error) {
// read header
buf := make([]byte, IPC_HEADER_SIZE)
buf := make([]byte, IpcHeaderSize)
_, err := ipc.socket.Read(buf)
if err != nil {
return nil, fmt.Errorf("failed to read header from ipc socket: %s", err)
}
if string(buf[:6]) != IPC_MAGIC {
if string(buf[:6]) != IpcMagix {
return nil, errors.New("got invalid response from IPC socket")
}