Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions notecard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/signal"
"strconv"
"io/ioutil"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -557,28 +557,41 @@ func main() {
}

if err == nil && actionRequest != "" {
var req notecard.Request
err = note.JSONUnmarshal([]byte(actionRequest), &req)
if err == nil {
var rsp notecard.Request
if actionInput == "" {
rsp, err = card.TransactionRequest(req)
var rspJSON []byte
rspJSON, err = card.TransactionJSON([]byte(actionRequest))
if !actionVerbose {
if err == nil {
fmt.Printf("%s\n", rspJSON)
}
}
if err == nil && actionOutput != "" {
var rsp notecard.Request
note.JSONUnmarshal(rspJSON, &rsp)
if rsp.Payload != nil {
err = ioutil.WriteFile(actionOutput, *rsp.Payload, 0644)
}
}
} else {
var req notecard.Request
note.JSONUnmarshal([]byte(actionRequest), &req)
var contents []byte
contents, err = ioutil.ReadFile(actionInput)
if err == nil {
req.Payload = &contents
rsp, err = card.TransactionRequest(req)
}
}
if !actionVerbose {
if err == nil {
rspJSON, _ := note.JSONMarshal(rsp)
fmt.Printf("%s\n", rspJSON)
}
}
if err == nil && actionOutput != "" && rsp.Payload != nil {
err = ioutil.WriteFile(actionOutput, *rsp.Payload, 0644)
if !actionVerbose {
if err == nil {
rspJSON, _ := note.JSONMarshal(rsp)
fmt.Printf("%s\n", rspJSON)
}
}
if err == nil && actionOutput != "" && rsp.Payload != nil {
err = ioutil.WriteFile(actionOutput, *rsp.Payload, 0644)
}
}
}
}
Expand Down Expand Up @@ -654,12 +667,12 @@ func main() {

// Process errors
if err != nil {
if actionRequest != "" && !actionVerbose {
fmt.Printf("{\"err\":%s}\n", strconv.Quote(err.Error()))
} else {
fmt.Printf("%s\n", err)
os.Exit(exitFail)
}
if actionRequest != "" && !actionVerbose {
fmt.Printf("{\"err\":%s}\n", strconv.Quote(err.Error()))
} else {
fmt.Printf("%s\n", err)
os.Exit(exitFail)
}
}

// Success
Expand Down
2 changes: 1 addition & 1 deletion notecard/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"bufio"
"bytes"
"fmt"
"os"
"io/ioutil"
"os"
"strings"
"time"

Expand Down