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: merge.go
    path of file: ./repos/kuma/pkg/plugins/policies/core/rules
    
    the code of the file until where you have to start completion: package rules

import (
	"encoding/json"
	"fmt"
	"reflect"
	"strings"

	jsonpatch "github.com/evanphx/json-patch/v5"
	"github.com/pkg/errors"

	core_model "github.com/kumahq/kuma/pkg/core/resources/model"
	"github.com/kumahq/kuma/pkg/util/pointer"
)

// indicates that all slices that start with this prefix will be appended, not replaced
const appendSlicesPrefix = "Append"

// MergeConfs returns list of confs that may be apply to separate sets of refs.
// In the usual case it has a single element but for MeshHTTPRoute it is keyed
// by hostname.
func MergeConfs(confs []interface{}) ([]interface{}, error) {
	if len(confs) == 0 {
		return nil, nil
	}

	// Sort the confs (potentially) into sets grouped by `mergeValues` fields
	taggedConfsList, err := handleMergeValues(confs)
	if err != nil {
		return nil, err
	}

	var interfaces []interface{}

	// Merge each tagged sets of confs
	for _, taggedConfs := range taggedConfsList {
		confs := taggedConfs.Confs

		result, err := mergeJSONPatches(confs)
		if err != nil {
			return nil, errors.Wrap(err, "couldn't merge JSON patches")
		}

		valueResult := reflect.ValueOf(result)
		// clear appendable slices, so we won't duplicate values of the
    
func handleMergeValues(confs []interface{}) ([]GroupedConfs, error) {
	confType := reflect.TypeOf(confs[0])

	// We construct a map of strings to confs
	var keyFieldIndex *int
	// Find a field tagged with `mergeValues`
	for fieldIndex := 0; fieldIndex < confType.NumField(); fieldIndex++ {
		field := confType.Field(fieldIndex)
		if field.Tag.Get(policyMergeTag) != mergeValues {
			continue
		}
		if field.Type.Kind() != reflect.Slice || field.Type.Elem().Kind() != reflect.String {
			return nil, fmt.Errorf("a mergeValues field must be a slice of strings")
		}

		keyFieldIndex = pointer.To(fieldIndex)
	}

	intermediateMergeMap := map[string][]reflect.Value{}

	// Track ordered mergeValues field values
	var orderedIntermediateKeys []string

	// Put every conf into the map for every `mergeValues` field value it has
	for _, conf := range confs {
		confVal := reflect.ValueOf(conf)
		// If there is no such `mergeValues` field, put everything under the
		// empty string
		keys := []string{""}
		if keyFieldIndex != nil {
			confKeys := confVal.Field(*keyFieldIndex)
			// Treat the empty list of values like "" in our map
			if confKeys.Len() > 0 {
				keys = confKeys.Interface().([]string)
			}
		}

		for _, key := range keys {
			keyedConf := reflect.New(confVal.Type())
			keyedConf.Elem().Set(confVal)
			values, ok := intermediateMergeMap[key]
			if !ok {
				orderedIntermediateKeys = append(orderedIntermediateKeys, key)
			}
			// Set the singular key on copies of these confs and add them to the
			// accumulator
			if key != "" {
				singleKeys := reflect.ValueOf([]string{key})
				keyedConf.Elem().Field(*keyFieldIndex).Set(singleKeys)
			}
			intermediateMergeMap[key] = append(values, keyedConf.Elem())
		}
	}

	var taggedValues []GroupedConfs
	for _, key := range orderedIntermediateKeys {
		confs, ok := intermediateMergeMap[key]
		if !ok {
			panic("internal merge error")
		}

		taggedValues = append(taggedValues, GroupedConfs{
			Confs: confs,
		})
	}

	return taggedValues, nil
}