1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/ids/ids.go
Carlos Alexandro Becker 8286402e3e
fix: better duplicate ID message
refs #1090

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2019-07-27 10:55:56 -03:00

37 lines
630 B
Go

// 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
}
// New IDs
func New(kind string) IDs {
return IDs{
ids: map[string]int{},
kind: kind,
}
}
// Inc increment the counter of the given id
func (i IDs) Inc(id string) {
i.ids[id]++
}
// 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,
)
}
}
return nil
}