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:
parent
96731b8fe0
commit
4370402c66
@ -7,22 +7,25 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "unknown"
|
var (
|
||||||
|
Version = "unknown"
|
||||||
var count int64
|
count int64
|
||||||
var detail bool
|
detail bool
|
||||||
var limit float64
|
limit float64
|
||||||
var interactive bool
|
interactive bool
|
||||||
var name string
|
name string
|
||||||
var oracle string
|
oracle string
|
||||||
var rarity string
|
rarity string
|
||||||
var set string
|
set string
|
||||||
var sinceBeginning bool
|
sinceBeginning bool
|
||||||
var sinceLastUpdate bool
|
sinceLastUpdate bool
|
||||||
var sortby string
|
sortby string
|
||||||
var cardType string
|
cardType string
|
||||||
var unique bool
|
unique bool
|
||||||
var foil bool
|
foil bool
|
||||||
|
address string
|
||||||
|
port uint64
|
||||||
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Version: Version,
|
Version: Version,
|
||||||
|
|||||||
@ -2,12 +2,15 @@ package serra
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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)
|
rootCmd.AddCommand(webCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,20 +33,18 @@ type Query struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startWeb() error {
|
func startWeb() error {
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.LoadHTMLGlob("templates/*.tmpl")
|
router.LoadHTMLGlob("templates/*.tmpl")
|
||||||
router.Static("/assets", "./assets")
|
router.Static("/assets", "./assets")
|
||||||
|
|
||||||
// Landing Page
|
// Landing page
|
||||||
router.GET("/", landingPage)
|
router.GET("/", landingPage)
|
||||||
|
|
||||||
router.Run(":8080")
|
router.Run(address + ":" + strconv.FormatUint(port, 10))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func landingPage(c *gin.Context) {
|
func landingPage(c *gin.Context) {
|
||||||
|
|
||||||
var query Query
|
var query Query
|
||||||
if c.ShouldBind(&query) == nil {
|
if c.ShouldBind(&query) == nil {
|
||||||
cards := Cards("", query.Set, query.Sort, query.Name, "", "")
|
cards := Cards("", query.Set, query.Sort, query.Name, "", "")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user