1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

feat(dataservices): abstract away some redundant code EE-5620 (#9110)

This commit is contained in:
andres-portainer 2023-06-20 17:51:34 -03:00 committed by GitHub
parent 7dc6a1559f
commit 716c196682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 315 additions and 824 deletions

View file

@ -2,11 +2,10 @@ package edgegroup
import (
"errors"
"fmt"
"github.com/portainer/portainer/api/dataservices"
portainer "github.com/portainer/portainer/api"
"github.com/rs/zerolog/log"
)
type ServiceTx struct {
@ -22,21 +21,11 @@ func (service ServiceTx) BucketName() string {
func (service ServiceTx) EdgeGroups() ([]portainer.EdgeGroup, error) {
var groups = make([]portainer.EdgeGroup, 0)
err := service.tx.GetAllWithJsoniter(
return groups, service.tx.GetAllWithJsoniter(
BucketName,
&portainer.EdgeGroup{},
func(obj interface{}) (interface{}, error) {
group, ok := obj.(*portainer.EdgeGroup)
if !ok {
log.Debug().Str("obj", fmt.Sprintf("%#v", obj)).Msg("failed to convert to EdgeGroup object")
return nil, fmt.Errorf("Failed to convert to EdgeGroup object: %s", obj)
}
groups = append(groups, *group)
return &portainer.EdgeGroup{}, nil
})
return groups, err
dataservices.AppendFn(&groups),
)
}
// EdgeGroup returns an Edge group by ID.