mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-08-28 04:46:42 -04:00
Move daemon code to dedicated package
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package main
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user