github.com/moov-io/imagecashletter@v0.10.1/cmd/readImageCashLetter/main.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "flag" 6 "fmt" 7 "log" 8 "os" 9 "runtime/pprof" 10 11 "github.com/moov-io/imagecashletter" 12 ) 13 14 var ( 15 fPath = flag.String("fPath", "BNK20181015-A.icl", "File Path") 16 cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") 17 18 flagJson = flag.Bool("json", false, "Output ICL File in JSON to stdout") 19 ) 20 21 func main() { 22 flag.Parse() 23 24 if *cpuprofile != "" { 25 f, err := os.Create(*cpuprofile) 26 if err != nil { 27 log.Fatal(err) 28 } 29 pprof.StartCPUProfile(f) 30 defer pprof.StopCPUProfile() 31 } 32 33 path := *fPath 34 35 // open a file for reading. Any io.Reader Can be used 36 f, err := os.Open(path) 37 38 if err != nil { 39 log.Printf("ERROR: Can not open file: %s: \n", err) 40 os.Exit(1) 41 } 42 43 r := imagecashletter.NewReader(f) 44 ICLFile, err := r.Read() 45 if err != nil { 46 fmt.Printf("Issue reading file: %+v \n", err) 47 } 48 49 // ensure we have a validated file structure 50 if ICLFile.Validate(); err != nil { 51 fmt.Printf("Could not validate entire read file: %v", err) 52 } 53 54 // If you trust the file but it's formatting is off building will probably resolve the malformed file. 55 if ICLFile.Create(); err != nil { 56 fmt.Printf("Could not build file with read properties: %v", err) 57 } 58 59 // Output file contents 60 if *flagJson { 61 if err := json.NewEncoder(os.Stdout).Encode(ICLFile); err != nil { 62 fmt.Printf("ERROR: problem writing ICL File to stdout: %v\n", err) 63 os.Exit(1) 64 } 65 } else { 66 fmt.Printf("Total record count: %v \n", ICLFile.Control.TotalRecordCount) 67 fmt.Printf("Cash Letter count: %v \n", ICLFile.Control.CashLetterCount) 68 fmt.Printf("File total Item count: %v \n", ICLFile.Control.TotalItemCount) 69 fmt.Printf("File total amount: %v \n", ICLFile.Control.FileTotalAmount) 70 } 71 }