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 ( import (
"os" "os"
+3 -3
View File
@@ -1,4 +1,4 @@
package main package daemon
import ( import (
"bytes" "bytes"
@@ -19,8 +19,8 @@ var daemonHash []byte
// RCWService provides an RPC method. // RCWService provides an RPC method.
type RCWService struct{} type RCWService struct{}
// StartDaemon should be called to start an RPC server. // Run should be called to start an RPC server.
func StartDaemon() { func Run() {
// store the hash of the daemon binary // store the hash of the daemon binary
daemonHash = getFileHash(binPath) daemonHash = getFileHash(binPath)
+3 -2
View File
@@ -1,4 +1,4 @@
package main package daemon
import ( import (
"log" "log"
@@ -6,7 +6,8 @@ import (
"net/rpc" "net/rpc"
) )
func CallDaemon() string { // Call connects to the RPC server and requests the passphrase.
func Call() string {
// connect to the UNIX domain socket // connect to the UNIX domain socket
conn, err := net.Dial("unix", socketPath) conn, err := net.Dial("unix", socketPath)
if err != nil { if err != nil {
+4 -3
View File
@@ -3,17 +3,18 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"rcw/daemon"
) )
func main() { func main() {
if len(os.Args) > 1 { if len(os.Args) > 1 {
switch os.Args[1] { switch os.Args[1] {
case "client": case "client":
fmt.Println("RPC Reply: " + CallDaemon()) fmt.Println("RPC Reply: " + daemon.Call())
default: default:
StartDaemon() daemon.Run()
} }
} else { } else {
StartDaemon() daemon.Run()
} }
} }