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: waf.go
    path of file: ./repos/streamdal/apps/server/vendor/gopkg.in/DataDog/dd-trace-go.v1/internal/appsec
    
    the code of the file until where you have to start completion: // Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.

package appsec

import (
	"errors"

	"github.com/DataDog/appsec-internal-go/limiter"
	waf "github.com/DataDog/go-libddwaf/v2"
	"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/dyngo"
	"gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/emitter/sharedsec"
	grpc "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/listener/grpcsec"
	http "gopkg.in/DataDog/dd-trace-go.v1/internal/appsec/listener/httpsec"
	"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
)

const (
	eventRulesVersionTag = "_dd.appsec.event_rules.version"
	eventRulesErrorsTag  = "_dd.appsec.event_rules.errors"
	eventRulesLoadedTag  = "_dd.appsec.event_rules.loaded"
	eventRulesFailedTag  = "_dd.appsec.event_rules.error_count"
	wafDurationTag       = "_dd.appsec.waf.duration"
	wafDurationExtTag    = "_dd.appsec.waf.duration_ext"
	wafTimeoutTag        = "_dd.appsec.waf.timeouts"
	wafVersionTag        = "_dd.appsec.waf.version"
)

type wafHandle struct {
	*waf.Handle
	// actions are tightly link to a ruleset, which is linked to a waf handle
	actions sharedsec.Actions
}

func (a *appsec) swapWAF(rules rulesFragment) (err error) {
	// Ins
    
func newWAFEventListeners(waf *wafHandle, cfg *Config, l limiter.Limiter) (listeners []dyngo.EventListener, err error) {
	// Check if there are addresses in the rule
	ruleAddresses := waf.Addresses()
	if len(ruleAddresses) == 0 {
		return nil, errors.New("no addresses found in the rule")
	}

	// Check which addresses are supported by what listener
	httpAddresses := make(map[string]struct{}, len(ruleAddresses))
	grpcAddresses := make(map[string]struct{}, len(ruleAddresses))
	notSupported := make([]string, 0, len(ruleAddresses))
	for _, address := range ruleAddresses {
		supported := false
		if http.SupportsAddress(address) {
			httpAddresses[address] = struct{}{}
			supported = true
		}
		if grpc.SupportsAddress(address) {
			grpcAddresses[address] = struct{}{}
			supported = true
		}
		if !supported {
			notSupported = append(notSupported, address)
		}
	}

	if len(notSupported) > 0 {
		log.Debug("appsec: the addresses present in the rules are partially supported: not supported=%v", notSupported)
	}

	// Register the WAF event listeners
	if len(httpAddresses) > 0 {
		log.Debug("appsec: creating http waf event listener of the rules addresses %v", httpAddresses)
		listeners = append(listeners, http.NewWAFEventListener(waf.Handle, waf.actions, httpAddresses, cfg.wafTimeout, &cfg.apiSec, l))
	}

	if len(grpcAddresses) > 0 {
		log.Debug("appsec: creating the grpc waf event listener of the rules addresses %v", grpcAddresses)
		listeners = append(listeners, grpc.NewWAFEventListener(waf.Handle, waf.actions, grpcAddresses, cfg.wafTimeout, l))
	}

	return listeners, nil
}