StarlioX/main.go

95 lines
2.1 KiB
Go
Raw Permalink Normal View History

2022-09-18 19:29:08 +03:00
package main
import (
"github.com/Redume/EveryNasa/api/controllers"
"github.com/Redume/EveryNasa/functions"
"github.com/Redume/EveryNasa/web/page"
2022-09-19 13:23:39 +03:00
"github.com/getlantern/systray"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/skratchdot/open-golang/open"
2022-09-18 19:29:08 +03:00
)
func main() {
go open.Run("http://localhost:3000")
2022-09-18 19:29:08 +03:00
go functions.Database()
go systray.Run(functions.Tray, functions.Quit)
go functions.StartWallpaper()
app := fiber.New()
2022-10-30 20:12:26 +03:00
app = fiber.New(fiber.Config{
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
if code == fiber.StatusNotFound {
return ctx.SendFile("./web/errors/404.html")
}
return nil
},
})
app.Static("/static", "./web/static")
app.Use(cors.New())
2022-10-02 12:24:00 +03:00
app.Get("/", func(c *fiber.Ctx) error {
return page.Gallery(c)
})
app.Get("/settings", func(c *fiber.Ctx) error {
return page.Settings(c)
})
app.Get("/about", func(c *fiber.Ctx) error {
return page.About(c)
})
app.Get("/favorite", func(c *fiber.Ctx) error {
return page.Favorite(c)
})
2022-10-02 12:24:00 +03:00
2022-10-30 20:12:26 +03:00
api := app.Group("/api")
update := api.Group("/update")
get := api.Group("/get")
add := api.Group("/add")
del := api.Group("/del")
2022-10-30 20:12:26 +03:00
create := api.Group("/create")
update.Post("/settings", func(c *fiber.Ctx) error {
return controllers.SettingsUpdate(c)
})
2022-10-30 20:12:26 +03:00
update.Post("/wallpaper", func(c *fiber.Ctx) error {
return controllers.WallpaperUpdate(c)
})
2022-10-30 20:12:26 +03:00
update.Post("/startup", func(c *fiber.Ctx) error {
return controllers.Startup(c)
})
2022-10-30 20:12:26 +03:00
create.Post("/label", func(c *fiber.Ctx) error {
return controllers.CreateLabel(c)
})
2022-10-02 12:24:00 +03:00
2022-10-30 20:12:26 +03:00
get.Get("/settings", func(c *fiber.Ctx) error {
return controllers.SettingsGet(c)
})
2022-09-18 19:29:08 +03:00
get.Get("/favorites", func(c *fiber.Ctx) error {
return controllers.GetFavorites(c)
})
add.Post("/favorite", func(c *fiber.Ctx) error {
return controllers.AddFavorite(c)
})
del.Post("/favorite", func(c *fiber.Ctx) error {
return controllers.DeleteFavorite(c)
})
err := app.Listen(":3000")
2022-09-18 19:29:08 +03:00
if err != nil {
return
2022-09-18 19:29:08 +03:00
}
}