func WriteSearchResultToResponse(rw http.ResponseWriter, searchResult *service.QueryResponse, options ...scimjson.Options) error {
	render := SearchResultRendering{
		Schemas:      []string{"urn:ietf:params:scim:api:messages:2.0:ListResponse"},
		TotalResults: searchResult.TotalResults,
		StartIndex:   searchResult.StartIndex,
		ItemsPerPage: searchResult.ItemsPerPage,
		Resources:    []json.RawMessage{},
	}
	for _, resource := range searchResult.Resources {
		raw, err := scimjson.Serialize(resource, options...)
		if err != nil {
			return err
		}
		render.Resources = append(render.Resources, raw)
	}
	rw.Header().Set("Content-Type", spec.ApplicationScimJson)
	return json.NewEncoder(rw).Encode(render)
}
WriteSearchResultToResponse writes the search result to http.ResponseWrite, respecting the attribute or excludedAttributes
specified through options. Any error during the process will be returned.
This method also sets Content-Type header to application/scim+json. This method does not set response status, which should
be set before calling this method.
package handlerutil
import (
	"encoding/json"
	"errors"
	scimjson "github.com/imulab/go-scim/pkg/v2/json"
	"github.com/imulab/go-scim/pkg/v2/prop"
	"github.com/imulab/go-scim/pkg/v2/service"
	"github.com/imulab/go-scim/pkg/v2/spec"
	"net/http"
)
func WriteResourceToResponse(rw http.ResponseWriter, resource *prop.Resource, options ...scimjson.Options) error {
	raw, jsonErr := scimjson.Serialize(resource, options...)
	if jsonErr != nil {
		return jsonErr
	}
	rw.Header().Set("Content-Type", spec.ApplicationScimJson)
	if location := resource.MetaLocationOrEmpty(); len(location) > 0 {
		rw.Header().Set("Location", location)
	}
	if version := resource.MetaVersionOrEmpty(); len(version) > 0 {
		rw.Header().Set("ETag", version)
	}
	_, writeErr := rw.Write(raw)
	return writeErr
}