func writeRows(listenSocket string, inputFormat string, tablesJSON string, dsn string) int { tablerInst := tabler.NewTabler() defer tablerInst.Close() go func() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM) s := <-c fmt.Println("tabler: received signal ", s) tablerInst.Close() os.Exit(0) }() err := tablerInst.Init(listenSocket, inputFormat) if err != nil { log.Printf("tabler: init-failure error=%v", err) return 1 } err = tablerInst.WriteRows(tablesJSON, dsn) if err != nil { log.Printf("tabler: write-failure error=%v", err) return 1 } return 0 }
func generateTables(listenSocket string, inputFormat string) int { tablerInst := tabler.NewTabler() defer tablerInst.Close() go func() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM) s := <-c fmt.Println("tabler: received signal ", s) tablerInst.Close() os.Exit(0) }() err := tablerInst.Init(listenSocket, inputFormat) if err != nil { log.Printf("tabler: init-failure error=%v", err) return 1 } var tablesJSON []byte tablesJSON, err = tablerInst.GenerateTables() if err != nil { log.Printf("tabler: generate-tables error=%v", err) return 1 } os.Stdout.Write(tablesJSON) return 0 }