Beispiel #1
0
func main() {
	flag.Parse()
	if showv {
		showVersion()
		return
	}

	appConfig, err := config.LoadAppConfig(conf)
	if err != nil {
		fmt.Printf("config load err: %s\n", err)
		os.Exit(-1)
	}

	if !debug {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.Default()
	r.Static("/assets", "./ui/assets")
	r.LoadHTMLGlob("ui/templates/*")
	r.Use(appConfigMiddleware(appConfig))

	if appConfig.Basic_auth.On {
		r.Use(gin.BasicAuth(gin.Accounts{appConfig.Basic_auth.Username: appConfig.Basic_auth.Password}))
	}

	r.GET("/", controller.Home)
	r.GET("/node", controller.Node)
	r.GET("/cluster", controller.Cluster)
	r.POST("/do", controller.Do)

	r.Run(listen)
}
Beispiel #2
0
func main() {
	appConfig, err := config.LoadAppConfig(APP_CONFIG_PATH)
	if err != nil {
		fmt.Println("发生错误:", err.Error())
		os.Exit(-1)
	}

	r := gin.Default()
	r.Static("/assets", "./ui/assets")
	r.LoadHTMLGlob("ui/templates/*")
	r.Use(appConfigMiddleware(appConfig))

	if appConfig.Basic_auth.On == "yes" {
		r.Use(gin.BasicAuth(gin.Accounts{appConfig.Basic_auth.Username: appConfig.Basic_auth.Password}))
	}

	r.GET("/", controller.Home)
	r.POST("/do", controller.Do)

	var port string
	flag.StringVar(&port, "listen", ":8080", "listen address")
	flag.Parse()
	r.Run(port)
}