campaigner/model/ticket.go

32 lines
580 B
Go
Raw Normal View History

2020-02-29 01:20:46 +01:00
package model
2020-02-29 14:17:34 +01:00
import (
"fmt"
)
2020-02-29 01:20:46 +01:00
type Ticket struct {
Filename string `json:"filename"`
LineNo int `json:"line_no"`
2020-02-29 14:18:27 +01:00
Text string `json:"text"`
2020-02-29 01:20:46 +01:00
}
2020-02-29 14:17:34 +01:00
2020-03-01 13:21:10 +01:00
func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket {
2020-02-29 14:17:34 +01:00
ticketMap := map[string]*Ticket{}
for _, t := range tickets {
2020-03-01 13:21:10 +01:00
if fileOnly {
t.Text = ""
t.LineNo = 0
ticketMap[t.Filename] = t
} else {
ticketMap[fmt.Sprintf("%s:%d", t.Filename, t.LineNo)] = t
}
2020-02-29 14:17:34 +01:00
}
cleanTickets := []*Ticket{}
for _, t := range ticketMap {
cleanTickets = append(cleanTickets, t)
}
return cleanTickets
}