Move daemon code to dedicated package

This commit is contained in:
2025-04-02 00:18:18 -04:00
parent 1cd123ab31
commit e3d5c83968
4 changed files with 11 additions and 9 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
package main
package daemon
import (
"os"
+3 -3
View File
@@ -1,4 +1,4 @@
package main
package daemon
import (
"bytes"
@@ -19,8 +19,8 @@ var daemonHash []byte
// RCWService provides an RPC method.
type RCWService struct{}
// StartDaemon should be called to start an RPC server.
func StartDaemon() {
// Run should be called to start an RPC server.
func Run() {
// store the hash of the daemon binary
daemonHash = getFileHash(binPath)
+3 -2
View File
@@ -1,4 +1,4 @@
package main
package daemon
import (
"log"
@@ -6,7 +6,8 @@ import (
"net/rpc"
)
func CallDaemon() string {
// Call connects to the RPC server and requests the passphrase.
func Call() string {
// connect to the UNIX domain socket
conn, err := net.Dial("unix", socketPath)
if err != nil {
+4 -3
View File
@@ -3,17 +3,18 @@ package main
import (
"fmt"
"os"
"rcw/daemon"
)
func main() {
if len(os.Args) > 1 {
switch os.Args[1] {
case "client":
fmt.Println("RPC Reply: " + CallDaemon())
fmt.Println("RPC Reply: " + daemon.Call())
default:
StartDaemon()
daemon.Run()
}
} else {
StartDaemon()
daemon.Run()
}
}