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: limit_iterator.go
    path of file: ./repos/FerretDB/internal/handler/common
    
    the code of the file until where you have to start completion: // Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed unde
    
func LimitIterator(iter types.DocumentsIterator, closer *iterator.MultiCloser, limit int64) types.DocumentsIterator {
	switch {
	case limit == 0:
		return iter
	case limit < 0:
		// limit parameter range should be handled by GetLimitParam.
		// aggregation limit stage allows limit of math.MaxInt64.
		// TODO https://github.com/FerretDB/FerretDB/issues/2255
		panic(fmt.Sprintf("invalid limit value: %d", limit))
	default:
		res := &limitIterator{
			iter:  iter,
			limit: uint32(limit),
		}
		closer.Add(res)

		return res
	}
}