Seraphim R. Pardee
10259ca924
Fix indentation. Use patched upload-artifact action. Update git URL in module. Divide workflows and give them order, add badges. Apparently workflow_run isn't supported yet... Update build to build container and push to registry. Fix some docker registry things. Use internal IPv4 for registry. Missed a spot. I think this order makes a difference. force HTTP use in login this? Use GITHUB_TOKEN instead. idk man i'm just gonna rebase this to clean the log Use a PAT. Copy files over correctly. blah
83 lines
2.2 KiB
Go
Executable File
83 lines
2.2 KiB
Go
Executable File
/*
|
|
* Copyright (C) 2021-2024 Seraphim R. Pardee
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"log"
|
|
"time"
|
|
|
|
"git.hl.srp.life/srp/bingo/routes"
|
|
"github.com/briandowns/spinner"
|
|
"github.com/dgraph-io/badger/v4"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/template/html/v2"
|
|
"github.com/mingrammer/cfmt"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
ListenAddress string
|
|
DisplayURL string
|
|
)
|
|
|
|
func init() {
|
|
runCmd.Flags().StringVarP(&ListenAddress, "listen", "l", "0.0.0.0:3005", "address:port to listen from")
|
|
rootCmd.AddCommand(runCmd)
|
|
}
|
|
|
|
var runCmd = &cobra.Command{
|
|
Use: "run",
|
|
Short: "Run the bingo server",
|
|
TraverseChildren: true,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
fmt.Println("🗑️ bingo by srp - https://sr.ht/~seraphimrp/bingo")
|
|
|
|
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
|
|
s.Suffix = " Running pre-flight checks"
|
|
s.FinalMSG = cfmt.Ssuccessln("✅ [info] Pre-flight checks complete")
|
|
s.Start()
|
|
|
|
engine := html.New("./views", ".html")
|
|
engine.AddFunc("safe", func(s string) template.HTML {
|
|
return template.HTML(s)
|
|
})
|
|
app := fiber.New(fiber.Config{
|
|
DisableStartupMessage: true,
|
|
Views: engine,
|
|
ViewsLayout: "layouts/main",
|
|
})
|
|
|
|
app.Static("/", "./static")
|
|
|
|
db, err := badger.Open(badger.DefaultOptions("./.bingodb").WithLogger(nil))
|
|
if err != nil {
|
|
s.FinalMSG = cfmt.Serrorln("😵 [err] couldn't establish the DB")
|
|
s.Stop()
|
|
log.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
routes.SetupRoutes(app, db)
|
|
s.Stop()
|
|
|
|
cfmt.Successf("🚀 [info] We have liftoff, bingo running at %s\n", ListenAddress)
|
|
app.Listen(ListenAddress)
|
|
},
|
|
}
|