Exemple #1
0
func main() {
	var err error
	var cp string
	var initial bool
	var conferr error

	flag.StringVarP(&cp, "conf", "c", "conf.yml", "Local path to configuration file.")
	flag.BoolVarP(&initial, "initial", "i", false, "Run the initial setup of the server.")
	flag.Parse()

	conferr = conf.Load(cp)
	if conferr != nil || initial {
		setup.Run()
	}
	if err = utils.EnsureDir(conf.C.UploadDir); err != nil {
		log.Fatal(err)
	}
	if db, err = gorm.Open("sqlite3", conf.C.DB); err != nil {
		log.Fatal(err)
	}
	db.AutoMigrate(&models.ResourceEntry{})

	go monitoring.Monit(&db)

	log.Printf("[INFO][System]\tStarted goploader server on port %d\n", conf.C.Port)
	if !conf.C.Debug {
		gin.SetMode(gin.ReleaseMode)
	}
	// Default router
	r := gin.Default()
	// Templates and static files
	r.LoadHTMLGlob("templates/*")
	r.Static("/static", "./assets")
	r.Static("/favicon.ico", "./assets/favicon.ico")
	// Routes
	r.GET("/", index)
	r.POST("/", create)
	r.GET("/v/:uniuri/:key", view)
	// Run
	r.Run(fmt.Sprintf(":%d", conf.C.Port))
}
Exemple #2
0
func main() {
	var err error
	var cp string
	var initial bool
	var r *gin.Engine

	tbox, _ := rice.FindBox("templates")
	abox, _ := rice.FindBox("assets")

	flag.StringVarP(&cp, "conf", "c", "conf.yml", "Local path to configuration file.")
	flag.BoolVarP(&initial, "initial", "i", false, "Run the initial setup of the server.")
	flag.Parse()

	if err = conf.Load(cp, !initial); err != nil || initial {
		setup.Run()
	}
	if err = database.Initialize(); err != nil {
		log.Fatal(err)
	}
	defer database.DB.Close()
	if err = models.Initialize(); err != nil {
		log.Fatal(err)
	}
	go monitoring.Monit()
	if r, err = router.Setup(tbox, abox); err != nil {
		log.Fatal(err)
	}

	logger.Info("server", "Started goploader server on port", conf.C.Port)
	if conf.C.ServeHTTPS {
		if err = http.ListenAndServeTLS(fmt.Sprintf(":%d", conf.C.Port), conf.C.SSLCert, conf.C.SSLPrivKey, r); err != nil {
			logger.Err("server", "Fatal error", err)
		}
	} else {
		if err = r.Run(fmt.Sprintf(":%d", conf.C.Port)); err != nil {
			logger.Err("server", "Fatal error", err)
		}
	}
}