♻️ Move web to sub-command
This commit is contained in:
parent
6c90679130
commit
213c9f6541
4 changed files with 45 additions and 31 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
gopub
|
||||||
40
commands/app.go
Normal file
40
commands/app.go
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
@ -11,9 +11,10 @@ var rootCmd = &cobra.Command{
|
||||||
Use: "gopub",
|
Use: "gopub",
|
||||||
Short: "gopub is a single-user ActivityPub instance",
|
Short: "gopub is a single-user ActivityPub instance",
|
||||||
Long: "...",
|
Long: "...",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
}
|
||||||
fmt.Println("Run a sub-command")
|
|
||||||
},
|
func init() {
|
||||||
|
rootCmd.AddCommand(AppCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
|
|
||||||
28
main.go
28
main.go
|
|
@ -1,37 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"codeberg.org/danjones000/gopub/commands"
|
"codeberg.org/danjones000/gopub/commands"
|
||||||
"codeberg.org/danjones000/gopub/config"
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
commands.Execute()
|
commands.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
type passReq struct {
|
|
||||||
Pass string `json:"pass"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func mainOld() {
|
|
||||||
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"))
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Reference in a new issue