github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/utils/summary/summary.go (about) 1 package summary 2 3 import ( 4 "encoding/json" 5 ) 6 7 type StatusType int 8 9 const ( 10 Success StatusType = iota 11 Failure 12 ) 13 14 var StatusTypes = []string{ 15 "success", 16 "failure", 17 } 18 19 func (statusType StatusType) MarshalJSON() ([]byte, error) { 20 return json.Marshal(StatusTypes[statusType]) 21 } 22 23 func New(err error) *Summary { 24 summary := &Summary{Totals: &Totals{}} 25 if err != nil { 26 summary.Status = Failure 27 } else { 28 summary.Status = Success 29 } 30 return summary 31 } 32 33 func (summary *Summary) Marshal() ([]byte, error) { 34 return json.Marshal(summary) 35 } 36 37 type Summary struct { 38 Status StatusType `json:"status"` 39 Totals *Totals `json:"totals"` 40 } 41 42 type Totals struct { 43 Success int `json:"success"` 44 Failure int `json:"failure"` 45 }