func initControllersRoute(r *gin.Engine, baseGroup string) error {
	authHandler := auth.GetAuth()
	r.Use(md.CheckAuthMiddleware(authHandler))
	logHandler, err := handlers.NewLogHandler(eventStorage)
	if err != nil {
		return err
	}
	jobHandler, err := handlers.NewJobHandler(objectStorage, logHandler)
	if err != nil {
		return err
	}
	ctrls := []APIController{
		api.NewJobAPIsController(jobHandler),
		api.NewAuthAPIsController(authHandler),
		api.NewLogsAPIsController(logHandler),
		api.NewKubeDLAPIsController(),
		api.NewTensorBoardController(),
		api.NewDataAPIsController(),
		api.NewDataSourceAPIsController(),
		api.NewCodeSourceAPIsController(),
	}
	router := r.Group(baseGroup)
	for _, ctrl := range ctrls {
		ctrl.RegisterRoutes(router)
	}
	return nil
}
initControllersRoute registers customized controllers and adds routes
package routers
import (
	"flag"
	md "github.com/alibaba/kubedl/console/backend/pkg/middleware"
	"github.com/alibaba/kubedl/console/backend/pkg/routers/api"
	"github.com/alibaba/kubedl/console/backend/pkg/utils"
	"net/http"
	"os"
	"path"
	"strings"
	"github.com/alibaba/kubedl/console/backend/pkg/auth"
	"github.com/alibaba/kubedl/console/backend/pkg/constants"
	"github.com/alibaba/kubedl/console/backend/pkg/handlers"
	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-contrib/static"
	"github.com/gin-gonic/gin"
	"k8s.io/klog"
)
func init() {
	flag.StringVar(&eventStorage, "event-storage", "apiserver", "event storage backend plugin name, persist events into backend if it's specified")
}
var (
	eventStorage string
	objectStorage = "proxy"
)
type APIController interface {
	RegisterRoutes(routes *gin.RouterGroup)
}
func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(
		gin.Logger(),
		gin.Recovery(),
		func(context *gin.Context) {
			context.Header("Cache-Control", "no-store,no-cache")
		},
	)
	r.NoRoute(
		utils.Redirect500,
		utils.Redirect403,
		utils.Redirect404,
	)
	store := cookie.NewStore([]byte("secret"))
	store.Options(sessions.Options{
		Path:     "/",
		HttpOnly: true,
		SameSite: http.SameSiteLaxMode,
	})
	r.Use(sessions.Sessions("loginSession", store))
	wd, err := os.Getwd()
	if err != nil {
		wd = "."
	}
	distDir := path.Join(wd, "dist")
	klog.Infof("kubedl-console working dir: %s", wd)
	r.LoadHTMLFiles(distDir + "/index.html")
	r.Use(
		static.Serve("/", static.LocalFile(distDir, true)),
		func(context *gin.Context) {
			if context.Request.URL == nil || context.Request.URL.Path == "" ||
				!strings.HasPrefix(context.Request.URL.Path, constants.ApiV1Routes) {
				context.HTML(http.StatusOK, "index.html", gin.H{})
			}
		},
	)
	if err = initControllersRoute(r, constants.ApiV1Routes); err != nil {
		klog.Errorf("init controller routes error: %v", err)
		panic(err)
	}
	return r
}