1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/ids/ids.go

37 lines
634 B
Go
Raw Normal View History

2019-05-07 12:18:35 +02:00
// Package ids provides id validation code used my multiple pipes.
package ids
import "fmt"
// IDs is the IDs type.
type IDs struct {
ids map[string]int
kind string
}
2019-05-07 12:18:35 +02:00
// New IDs.
func New(kind string) IDs {
return IDs{
ids: map[string]int{},
kind: kind,
}
2019-05-07 12:18:35 +02:00
}
// Inc increment the counter of the given id.
func (i IDs) Inc(id string) {
i.ids[id]++
2019-05-07 12:18:35 +02:00
}
// Validate errors if there are any ids with counter > 1.
func (i IDs) Validate() error {
for id, count := range i.ids {
if count > 1 {
return fmt.Errorf(
"found %d %s with the ID '%s', please fix your config",
count, i.kind, id,
)
2019-05-07 12:18:35 +02:00
}
}
return nil
}