campaigner/model/ticket.go
2020-03-01 13:21:10 +01:00

31 lines
580 B
Go

package model
import (
"fmt"
)
type Ticket struct {
Filename string `json:"filename"`
LineNo int `json:"line_no"`
Text string `json:"text"`
}
func RemoveDuplicateTickets(tickets []*Ticket, fileOnly bool) []*Ticket {
ticketMap := map[string]*Ticket{}
for _, t := range tickets {
if fileOnly {
t.Text = ""
t.LineNo = 0
ticketMap[t.Filename] = t
} else {
ticketMap[fmt.Sprintf("%s:%d", t.Filename, t.LineNo)] = t
}
}
cleanTickets := []*Ticket{}
for _, t := range ticketMap {
cleanTickets = append(cleanTickets, t)
}
return cleanTickets
}