This commit is contained in:
@@ -43,6 +43,7 @@ const (
|
||||
Pushed
|
||||
Pulled
|
||||
UpToDate
|
||||
Done
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -81,7 +82,7 @@ func (s *Syncer) Sync() {
|
||||
for _, g := range games {
|
||||
r, err := remote.One(g.ID)
|
||||
if err != nil {
|
||||
s.errorCallback(fmt.Errorf("%w: %s", ErrDatastore, err), g)
|
||||
continue
|
||||
}
|
||||
if r.URL != s.cli.BaseURL() {
|
||||
continue
|
||||
@@ -90,6 +91,7 @@ func (s *Syncer) Sync() {
|
||||
s.errorCallback(err, g)
|
||||
}
|
||||
}
|
||||
s.stateCallback(Done, repository.Metadata{})
|
||||
}
|
||||
|
||||
func (s *Syncer) sync(g repository.Metadata) error {
|
||||
|
||||
40
pkg/tools/iterator/iterator.go
Normal file
40
pkg/tools/iterator/iterator.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package iterator
|
||||
|
||||
type (
|
||||
Iterator[T any] struct {
|
||||
index int
|
||||
values []T
|
||||
}
|
||||
)
|
||||
|
||||
func New[T any](values []T) *Iterator[T] {
|
||||
return &Iterator[T]{
|
||||
values: values,
|
||||
}
|
||||
}
|
||||
|
||||
func (it *Iterator[T]) Next() bool {
|
||||
if len(it.values) == it.index {
|
||||
return false
|
||||
}
|
||||
it.index += 1
|
||||
return true
|
||||
}
|
||||
|
||||
func (it *Iterator[T]) Value() T {
|
||||
if len(it.values) == 0 {
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
|
||||
if len(it.values) == it.index {
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
|
||||
return it.values[it.index]
|
||||
}
|
||||
|
||||
func (it *Iterator[T]) IsEmpty() bool {
|
||||
return len(it.values) == 0
|
||||
}
|
||||
Reference in New Issue
Block a user