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: BaseController.go
    path of file: ./repos/BookStack/controllers/api
    
    the code of the file until where you have to start completion: package api

import (
	"compress/gzip"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"strconv"
	"strings"
	"sync"
	"time"

	"github.com/astaxie/beego/orm"

	"github.com/TruthHun/BookStack/utils"

	"github.com/TruthHun/BookStack/models"

	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
	Token   string
	Version string
}

type APIResponse struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type APIUser struct {
	Uid         int    `json:"uid"`
	Token       string `json:"token,omitempty"`
	Account     string `json:"username,omitempty"` //对应 member.account
	Nickname    string `json:"nickname"`
	Email       string `json:"email,omitempty"`
	Phone       string `json:"phone,omitempty"`
	Avatar      string `json:"avatar"`
	Description string `json:"intro,omitempty"`
}

type APIBook struct {
	BookId      int       `json:"book_id"`
	BookName    string    `json:"book_name"`
	Identify    string    `json:"identify"`
	OrderIndex  int       `json:"sort"`
	Description string    `json:"description"`
	
    
func (this *BaseController) Prepare() {
	//在微信小程序中：网络请求的 referer 是不可以设置的，格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html，其中 {appid} 为小程序的 appid，{version} 为小程序的版本号，版本号为 0 表示为开发版。
	appId := strings.ToLower(beego.AppConfig.DefaultString("appid", ""))
	limitReferer := beego.AppConfig.DefaultBool("limitReferer", false)
	if appId != "" && limitReferer && beego.AppConfig.String("runmode") != "dev" { // 限定请求的微信小程序的appid
		prefix := fmt.Sprintf("https://servicewechat.com/%v/", appId)
		if !strings.HasPrefix(strings.ToLower(this.Ctx.Request.Referer()), prefix) {
			this.Response(http.StatusNotFound, "not found")
		}
	}
	this.Token = this.Ctx.Request.Header.Get("Authorization")
	this.Version = this.Ctx.Request.Header.Get("x-version")

	if !models.AllowVisitor && this.isLogin() == 0 { // 不允许游客访问，则除了部分涉及登录的API外，一律提示先登录
		allowAPIs := map[string]bool{
			beego.URLFor("CommonController.Login"):         true,
			beego.URLFor("CommonController.LoginByWechat"): true,
			//beego.URLFor("CommonController.LoginBindWechat"): true, // 这个接口属于绑定信息的，属于注册接口。
		}
		if _, ok := allowAPIs[this.Ctx.Request.URL.Path]; !ok {
			this.Response(http.StatusBadRequest, messageMustLogin)
		}
	}

	if !models.AllowRegister { // 如果不允许注册，则不允许用户访问注册相关的接口，其他接口可以访问
		denyAPIs := map[string]bool{
			beego.URLFor("CommonController.LoginBindWechat"): true, // 这个接口属于绑定信息的，属于注册接口。
			beego.URLFor("CommonController.Register"):        true, // 这个接口属于绑定信息的，属于注册接口。
		}
		if _, ok := denyAPIs[this.Ctx.Request.URL.Path]; ok {
			this.Response(http.StatusBadRequest, messageForbidRegister)
		}
	}

}