feat: refactor webCmd and improve UI consistency

- Add `address` and `port` flags to `webCmd`
- Change the landing page comment to start with a lowercase letter

Signed-off-by: Corentin Barreau <corentin@archive.org>
This commit is contained in:
Corentin Barreau 2023-04-24 15:12:23 +02:00 committed by Florian Baumann
parent 38ffc25b44
commit fa59a96db2
2 changed files with 24 additions and 20 deletions

View File

@ -7,22 +7,25 @@ import (
"github.com/spf13/cobra"
)
var Version = "unknown"
var count int64
var detail bool
var limit float64
var interactive bool
var name string
var oracle string
var rarity string
var set string
var sinceBeginning bool
var sinceLastUpdate bool
var sortby string
var cardType string
var unique bool
var foil bool
var (
Version = "unknown"
count int64
detail bool
limit float64
interactive bool
name string
oracle string
rarity string
set string
sinceBeginning bool
sinceLastUpdate bool
sortby string
cardType string
unique bool
foil bool
address string
port uint64
)
var rootCmd = &cobra.Command{
Version: Version,

View File

@ -2,12 +2,15 @@ package serra
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
)
func init() {
webCmd.Flags().StringVarP(&address, "address", "a", "0.0.0.0", "Address to listen on")
webCmd.Flags().Uint64VarP(&port, "port", "p", 8080, "Port to listen on")
rootCmd.AddCommand(webCmd)
}
@ -30,20 +33,18 @@ type Query struct {
}
func startWeb() error {
router := gin.Default()
router.LoadHTMLGlob("templates/*.tmpl")
router.Static("/assets", "./assets")
// Landing Page
// Landing page
router.GET("/", landingPage)
router.Run(":8080")
router.Run(address + ":" + strconv.FormatUint(port, 10))
return nil
}
func landingPage(c *gin.Context) {
var query Query
if c.ShouldBind(&query) == nil {
cards := Cards("", query.Set, query.Sort, query.Name, "", "")