Begin restructuring the project

This commit is contained in:
Jan Philipp Timme 2019-01-01 15:46:35 +01:00
parent eadaf8d420
commit 9e19df62ed
2 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
package parser package mailq
import ( import (
"bufio" "bufio"

18
main.go
View File

@ -10,7 +10,7 @@ import (
) )
import ( import (
"mailq-inspector/parser" "mailq-inspector/mailq"
) )
var settings = make(map[string]string) var settings = make(map[string]string)
@ -49,7 +49,7 @@ func showQueue() {
fmt.Printf("Could not fetch queue entries: %s\n", err.Error()) fmt.Printf("Could not fetch queue entries: %s\n", err.Error())
os.Exit(1) os.Exit(1)
} }
sortConfig := parser.NewSortConfig().By("Status", "ASC").By("Sender", "ASC").By("Recipients", "DESC") sortConfig := mailq.NewSortConfig().By("Status", "ASC").By("Sender", "ASC").By("Recipients", "DESC")
queue.Sort(sortConfig) queue.Sort(sortConfig)
if settings["usePager"] == "true" { if settings["usePager"] == "true" {
pagerReader, pagerWriter := io.Pipe() pagerReader, pagerWriter := io.Pipe()
@ -64,7 +64,7 @@ func showQueue() {
} }
} }
func printQueue(queue parser.MailQ, writer io.Writer) { func printQueue(queue mailq.MailQ, writer io.Writer) {
if settings["outputFormat"] == "human" { if settings["outputFormat"] == "human" {
queue.PrintHumanReadable(writer) queue.PrintHumanReadable(writer)
} else if settings["outputFormat"] == "machine" { } else if settings["outputFormat"] == "machine" {
@ -89,7 +89,7 @@ func launchPager(reader *io.PipeReader, pagerDone chan<- bool) {
} }
} }
func fetchQueue() (parser.MailQ, error) { func fetchQueue() (mailq.MailQ, error) {
if settings["mailqCommandArgs"] == "" { if settings["mailqCommandArgs"] == "" {
return readFromCmd(exec.Command(settings["mailqCommand"])) return readFromCmd(exec.Command(settings["mailqCommand"]))
} else { } else {
@ -97,17 +97,17 @@ func fetchQueue() (parser.MailQ, error) {
} }
} }
func readFromCmd(cmd *exec.Cmd) (parser.MailQ, error) { func readFromCmd(cmd *exec.Cmd) (mailq.MailQ, error) {
stdout, err := cmd.StdoutPipe() stdout, err := cmd.StdoutPipe()
if err != nil { if err != nil {
return parser.MailQ{}, err return mailq.MailQ{}, err
} }
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return parser.MailQ{}, err return mailq.MailQ{}, err
} }
result, resultError := parser.ParseMailQ(stdout) result, resultError := mailq.ParseMailQ(stdout)
if err := cmd.Wait(); err != nil { if err := cmd.Wait(); err != nil {
return parser.MailQ{}, err return mailq.MailQ{}, err
} }
return result, resultError return result, resultError
} }