1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/ids/ids.go
Carlos Alexandro Becker 69c8a502db
chore(deps): bump github.com/golangci/golangci-lint from 1.23.7 to 1.27.0 (#1563)
* chore(deps): bump github.com/golangci/golangci-lint from 1.23.7 to 1.27.0

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-05-26 00:48:10 -03:00

37 lines
634 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
}