fixed logs and config locations, updated connection closure handling

This commit is contained in:
2025-12-10 11:22:09 +01:00
parent 709abb30fa
commit 27609dba2b
7 changed files with 75 additions and 24 deletions

51
util/util.go Normal file
View File

@@ -0,0 +1,51 @@
package util
import (
"os"
"path/filepath"
"time"
"github.com/gorilla/websocket"
)
func GetPath() string {
exe, err := os.Executable()
if err != nil {
return ""
}
exe, err = filepath.EvalSymlinks(exe)
if err != nil {
}
return filepath.Dir(exe)
}
func NormalizePath(path string) string {
return filepath.Clean(filepath.FromSlash(path))
}
func NormalizeLogPath(path string) string {
if filepath.IsAbs(path) {
return path
}
return NormalizePath(filepath.Join(GetPath(), path))
}
//
func CloseConnWithControlMessage(conn *websocket.Conn, typ int, text string) {
_ = conn.SetWriteDeadline(time.Now().Add(time.Second))
_ = conn.WriteControl(
typ, websocket.FormatCloseMessage(typ, text), time.Now().Add(time.Second),
)
_ = conn.Close()
}
func CloseConn(conn *websocket.Conn) {
CloseConnWithControlMessage(
conn, websocket.CloseNormalClosure,
"Disconnecting.",
)
}