[#973] node: Resolve perfsprint linter

`fmt.Errorf can be replaced with errors.New` and `fmt.Sprintf can be replaced with string addition`

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-03-11 17:55:50 +03:00
parent 66a26b7775
commit d433b49265
39 changed files with 143 additions and 72 deletions

View file

@ -1,6 +1,7 @@
package sdnotify
import (
"errors"
"fmt"
"net"
"os"
@ -13,14 +14,19 @@ const (
ReloadingEnabled = "RELOADING=1"
)
var socket *net.UnixAddr
var (
socket *net.UnixAddr
errSocketVariableIsNotPresent = errors.New("\"NOTIFY_SOCKET\" environment variable is not present")
errSocketIsNotInitialized = errors.New("socket is not initialized")
)
// Initializes socket with provided name of
// environment variable.
func InitSocket() error {
notifySocket := os.Getenv("NOTIFY_SOCKET")
if notifySocket == "" {
return fmt.Errorf("\"NOTIFY_SOCKET\" environment variable is not present")
return errSocketVariableIsNotPresent
}
socket = &net.UnixAddr{
Name: notifySocket,
@ -38,14 +44,14 @@ func FlagAndStatus(status string) error {
// Status sends systemd notify STATUS=%s{status}.
func Status(status string) error {
return Send(fmt.Sprintf("STATUS=%s", status))
return Send("STATUS=" + status)
}
// Send state through the notify socket if any.
// If the notify socket was not detected, it returns an error.
func Send(state string) error {
if socket == nil {
return fmt.Errorf("socket is not initialized")
return errSocketIsNotInitialized
}
conn, err := net.DialUnix(socket.Net, nil, socket)
if err != nil {