This repository has been archived on 2025-11-25. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
combluotion-old/commands/app.go

40 lines
822 B
Go
Raw Normal View History

2023-03-24 13:03:21 -05:00
package commands
import (
"codeberg.org/danjones000/gopub/config"
"github.com/gofiber/fiber/v2"
"github.com/spf13/cobra"
"log"
)
type passReq struct {
Pass string `json:"pass"`
}
func app(cmd *cobra.Command, args []string) {
app := fiber.New()
conf := config.GetConfig()
app.Get("/", func(c *fiber.Ctx) error {
return c.JSON(&conf)
})
app.Post("/check_pass", func(c *fiber.Ctx) error {
req := new(passReq)
if err := c.BodyParser(req); err != nil {
panic(err)
}
return c.JSON(config.CheckPassword(req.Pass))
})
log.Fatal(app.Listen(":3000"))
}
var AppCmd = &cobra.Command{
Use: "app",
Short: "Run the gopub webapp",
Long: `This is the main command. This will start the application, and keep it running.
You may want to run this from something like supervisor or systemd`,
Run: app,
}