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: release.go
    path of file: ./repos/porter/api/server/authz
    
    the code of the file until where you have to start completion: package authz

import (
	"context"
	"fmt"
	"net/http"
	"strings"

	"github.com/porter-dev/porter/api/server/shared/apierrors"
	"github.com/porter-dev/porter/api/server/shared/config"
	"github.com/porter-dev/porter/api/server/shared/requestutils"
	"github.com/porter-dev/porter/api/types"
	"github.com/porter-dev/porter/internal/models"
	"github.com/porter-dev/porter/internal/telemetry"
	"github.com/stefanmcshane/helm/pkg/release"
)

type ReleaseScopedFactory struct {
	config *config.
    
func (p *ReleaseScopedMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	ctx, span := telemetry.NewSpan(r.Context(), "middleware-release-scope")
	defer span.End()

	cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)

	helmAgent, err := p.agentGetter.GetHelmAgent(ctx, r, cluster, "")
	if err != nil {
		apierrors.HandleAPIError(p.config.Logger, p.config.Alerter, w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError), true)
		return
	}

	// get the name of the application
	reqScopes, _ := ctx.Value(types.RequestScopeCtxKey).(map[types.PermissionScope]*types.RequestAction)
	name := reqScopes[types.ReleaseScope].Resource.Name

	// get the version for the application
	version, _ := requestutils.GetURLParamUint(r, types.URLParamReleaseVersion)

	release, err := helmAgent.GetRelease(ctx, name, int(version), false)
	if err != nil {
		// ugly casing since at the time of this commit Helm doesn't have an errors package.
		// so we rely on the Helm error containing "not found"
		if strings.Contains(err.Error(), "not found") {
			apierrors.HandleAPIError(p.config.Logger, p.config.Alerter, w, r, apierrors.NewErrPassThroughToClient(
				fmt.Errorf("release not found"),
				http.StatusNotFound,
			), true)
		} else {
			apierrors.HandleAPIError(p.config.Logger, p.config.Alerter, w, r, apierrors.NewErrInternal(err), true)
		}

		return
	}

	ctx = NewReleaseContext(ctx, release)
	r = r.Clone(ctx)
	p.next.ServeHTTP(w, r)
}