Take requests off the socket
authorGreg Hurrell <greg@hurrell.net>
Thu, 8 Dec 2016 03:10:02 +0000 (19:10 -0800)
committerGreg Hurrell <greg@hurrell.net>
Thu, 8 Dec 2016 03:10:02 +0000 (19:10 -0800)
Test with:

echo '{"service":"test item 1000","account":"test name"}' | nc -U ~/.passage.sock

passage.go

index 235671210a633daa46349d26946a447b8d0bcae4..5603036a14a59583fa19aa68f03f9a3180a458af 100644 (file)
@@ -55,10 +55,9 @@ func getSockPath() string {
 
 func handleConnection(conn net.Conn) {
        defer conn.Close()
-
+       decoder := json.NewDecoder(conn)
        var request Request
-       socketData := []byte("{\"service\":\"test item 1000\",\"account\":\"test name\"}")
-       err := json.Unmarshal(socketData, &request)
+       err := decoder.Decode(&request)
        if err != nil {
                log.Print(err)
                return
@@ -72,9 +71,9 @@ func handleConnection(conn net.Conn) {
        query.SetReturnData(true)
        results, err := keychain.QueryItem(query)
        if err != nil {
-               fmt.Printf("error\n")
+               log.Print(err)
        } else if len(results) != 1 {
-               fmt.Printf("not found\n")
+               log.Print("not found")
        } else {
                password := string(results[0].Data)
                fmt.Printf(password)