You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: dockerhelper.go
    path of file: ./repos/dyrectorio/golang/pkg/dagent/utils
    
    the code of the file until where you have to start completion: // These functions are dagent specific, yet it's more closely related to dockerHelper itself.
// Latter implementation is not straightforward at this moment as it would introduce circular dependencies

package utils

import (
	"context"
	"errors"
	"fmt"
	"strings"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/events"
	"github.com/docker/docker/client"

	"github.com/dyrector-io/dyrectorio/golang/internal/grpc"
	dockerHelper "github.com/dyrector-io/dyrectorio/golang/internal/helper/docker"
	"github.com/dyrector-io/dyrectorio/golang/internal/label"
	"github.com/dyrector-io/dyrectorio/golang/internal/mapper"
	"github.com/dyrector-io/dyrectorio/golang/internal/util"
	"github.com/dyrector-io/dyrectorio/protobuf
    
func WatchContainersByPrefix(ctx context.Context, cli client.APIClient, prefix string) (*grpc.ContainerWatchContext, error) {
	var err error
	var containers []types.Container
	if prefix == "" {
		containers, err = dockerHelper.GetAllContainers(ctx)
	} else {
		containers, err = dockerHelper.GetAllContainersByLabel(ctx, label.GetPrefixLabelFilter(prefix))
	}
	if err != nil {
		return nil, err
	}

	eventChannel := make(chan []*common.ContainerStateItem)
	errorChannel := make(chan error)

	chanMessages, chanErrors := cli.Events(ctx, types.EventsOptions{})

	go func(ctx context.Context, prefix string, chanMessages <-chan events.Message, chanErrors <-chan error) {
		eventChannel <- mapper.MapContainerStateList(containers, prefix)

		for {
			select {
			case <-ctx.Done():
				return
			case eventError := <-chanErrors:
				errorChannel <- eventError
				return
			case eventMessage := <-chanMessages:
				var changed *common.ContainerStateItem
				changed, err = messageToStateItem(ctx, prefix, &eventMessage)
				if err != nil {
					errorChannel <- err
					return
				} else if changed != nil {
					eventChannel <- []*common.ContainerStateItem{
						changed,
					}
				}
				break
			}
		}
	}(ctx, prefix, chanMessages, chanErrors)

	return &grpc.ContainerWatchContext{
		Events: eventChannel,
		Error:  errorChannel,
	}, nil
}