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: apirenamenotebook.go
    path of file: ./repos/nodebook/src/core/httphandler
    
    the code of the file until where you have to start completion: package httphandler

import (
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"path"
	"strings"

	"github.com/gorilla/mux"
	"github.com/netgusto/nodebook/src/core/shared/service"
	"github.com/netgusto/nodebook/src/core/shared/types"
	"github.com/pkg/errors"
)

func ApiNotebookRenameHandler(notebookRegistry *service.NotebookRegistry, csrfService *service.CSRFService, routes *service.Routes) HTTPHandler {
	return func(res http.ResponseWr
    
func renameNotebook(notebook types.Notebook, newname string, notebookregistry *service.NotebookRegistry) (types.Notebook, error) {

	newabsdir := path.Join(path.Dir(notebook.GetAbsdir()), newname)
	_, err := os.Stat(newabsdir)
	if err == nil {
		return nil, fmt.Errorf("Could not rename notebook %s: the new dir %s already exists", notebook.GetName(), newabsdir)
	}

	if err = os.Rename(notebook.GetAbsdir(), newabsdir); err != nil {
		return nil, errors.Wrapf(err, "Could not rename notebook %s to %s", notebook.GetName(), newname)
	}

	renamedNotebook, err := notebookregistry.Renamed(notebook, newname)
	if err != nil {
		return nil, errors.Wrapf(err, "Could not rename notebook %s to %s", notebook.GetName(), newname)
	}

	return renamedNotebook, nil
}