58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/labstack/echo/v5"
|
|
"github.com/labstack/echo/v5/middleware"
|
|
echoSwagger "github.com/swaggo/echo-swagger"
|
|
"gitnet.fr/deblan/borgmatic-monitor/docs"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/database/model"
|
|
"gitnet.fr/deblan/borgmatic-monitor/pkg/web"
|
|
)
|
|
|
|
func main() {
|
|
database.Init()
|
|
|
|
db := database.GetDb()
|
|
|
|
db.AutoMigrate(model.Host{})
|
|
db.AutoMigrate(model.Info{})
|
|
|
|
e := echo.New()
|
|
e.Use(middleware.RequestLogger())
|
|
|
|
e.GET("/", web.Hosts)
|
|
e.GET("/host/:id", web.Host)
|
|
e.POST("/api/v1/borgmatic/infos", web.ApiBorgmaticInfos)
|
|
|
|
docs.SwaggerInfo.Title = "Borgmatic monitor"
|
|
docs.SwaggerInfo.Description = "API"
|
|
docs.SwaggerInfo.Version = "1.0"
|
|
docs.SwaggerInfo.BasePath = "/"
|
|
docs.SwaggerInfo.Schemes = []string{"http", "https"}
|
|
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
|
|
|
if err := e.Start(":1323"); err != nil {
|
|
e.Logger.Error("failed to start server", "error", err)
|
|
}
|
|
|
|
// var hosts []model.Host
|
|
//
|
|
// db.Model(model.Host{}).Find(&hosts)
|
|
//
|
|
// for _, host := range hosts {
|
|
// fmt.Printf("%+v\n", host)
|
|
// }
|
|
|
|
// if content, err := ioutil.ReadFile("example.json"); err == nil {
|
|
// var res borgmatic.Infos
|
|
//
|
|
// err := json.Unmarshal(content, &res)
|
|
//
|
|
// if err != nil {
|
|
// fmt.Printf("%+v\n", err)
|
|
// }
|
|
//
|
|
// fmt.Printf("%+v\n", res)
|
|
// }
|
|
}
|