コード例 #1
0
ファイル: config.go プロジェクト: mdeheij/monitoring
//TestConfiguration checks if configuration can be loaded and shows amount of services
func TestConfiguration() error {
	services := loader.FindServices()
	length := len(services)
	log.Info("Length:", length, "services")
	if length > 0 {
		return nil
	} else {
		return errors.New("Amount of services is invalid.")
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: mdeheij/monitoring
//Setup initializes routers, login and services.
func Setup() {

	if configuration.Debug {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}

	r := gin.New()

	r.Use(cors.Middleware(cors.Config{
		Origins:         "*",
		Methods:         "GET, PUT, POST, DELETE",
		RequestHeaders:  "Origin, Authorization, Content-Type",
		ExposedHeaders:  "",
		MaxAge:          50 * time.Second,
		Credentials:     true,
		ValidateHeaders: false,
	}))

	r.SetHTMLTemplate(pages.Template)
	r.GET("/", pages.Homepage)

	serviceGroup := r.Group("/api/", AuthRequired())
	{
		serviceGroup.GET("/services/:identifier/update", services.Update)
		serviceGroup.GET("/services/:identifier/reschedule", services.Reschedule)
		serviceGroup.GET("/services/:identifier", services.Show)
		serviceGroup.GET("/services", services.List)
	}

	systemAPI := r.Group("/api/system/", AuthRequired())
	{
		systemAPI.GET("/start", system.Start)
		systemAPI.GET("/stop", system.Stop)
		systemAPI.GET("/reload", system.Reload)
	}

	log.Notice("Starting webserver..")
	log.Info("API listening on http://" + configuration.C.API.Address)

	r.Run(configuration.C.API.Address)
}