github.com/almamedia/fargate@v0.2.4-0.20220704071213-7b5b3d27c5eb/cmd/mock/output.go (about) 1 package mock 2 3 import ( 4 "fmt" 5 "sync" 6 ) 7 8 type Output struct { 9 DebugMsgs []string 10 Exited bool 11 FatalMsgs []Fatal 12 InfoMsgs []string 13 KeyValueMsgs map[string]string 14 SayMsgs []string 15 Tables []Table 16 WarnMsgs []string 17 lock sync.Mutex 18 } 19 20 type Table struct { 21 Header string 22 Rows [][]string 23 } 24 25 type Fatal struct { 26 Errors []error 27 Msg string 28 } 29 30 func (o *Output) Info(msg string, a ...interface{}) { 31 o.lock.Lock() 32 defer o.lock.Unlock() 33 34 o.InfoMsgs = append(o.InfoMsgs, fmt.Sprintf(msg, a...)) 35 } 36 37 func (o *Output) Warn(msg string, a ...interface{}) { 38 o.lock.Lock() 39 defer o.lock.Unlock() 40 41 o.WarnMsgs = append(o.WarnMsgs, fmt.Sprintf(msg, a...)) 42 } 43 44 func (o *Output) Fatal(err error, msg string, a ...interface{}) { 45 o.Fatals([]error{err}, msg, a...) 46 } 47 48 func (o *Output) Fatals(errs []error, msg string, a ...interface{}) { 49 o.lock.Lock() 50 defer o.lock.Unlock() 51 52 o.FatalMsgs = append(o.FatalMsgs, Fatal{Msg: fmt.Sprintf(msg, a...), Errors: errs}) 53 o.Exited = true 54 } 55 56 func (o *Output) Say(msg string, indent int, a ...interface{}) { 57 o.lock.Lock() 58 defer o.lock.Unlock() 59 60 o.SayMsgs = append(o.SayMsgs, fmt.Sprintf(msg, a...)) 61 } 62 63 func (o *Output) Debug(msg string, a ...interface{}) { 64 o.lock.Lock() 65 defer o.lock.Unlock() 66 67 o.DebugMsgs = append(o.DebugMsgs, fmt.Sprintf(msg, a...)) 68 } 69 70 func (o *Output) KeyValue(key, value string, indent int, a ...interface{}) { 71 o.lock.Lock() 72 defer o.lock.Unlock() 73 74 if o.KeyValueMsgs == nil { 75 o.KeyValueMsgs = make(map[string]string) 76 } 77 78 o.KeyValueMsgs[key] = value 79 } 80 81 func (o *Output) Table(header string, rows [][]string) { 82 o.lock.Lock() 83 defer o.lock.Unlock() 84 85 o.Tables = append(o.Tables, Table{Header: header, Rows: rows}) 86 } 87 88 func (o *Output) LineBreak() { 89 }