You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/cli/main.go

57 lines
1.2 KiB
Go

11 months ago
//
// main.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//
package main
import (
3 weeks ago
"github.com/veypi/vbase"
"github.com/veypi/vbase/cfg"
"github.com/veypi/vbase/models"
"github.com/veypi/vigo"
"github.com/veypi/vigo/flags"
"github.com/veypi/vigo/logv"
11 months ago
)
10 months ago
var cliOpts = &struct {
2 weeks ago
Host string `json:"host"`
Port int `json:"port" short:"p"`
3 weeks ago
*cfg.Options
10 months ago
}{
2 weeks ago
Host: "0.0.0.0",
Port: 4000,
Options: cfg.Config,
10 months ago
}
10 months ago
3 weeks ago
var (
cmdMain = flags.New("app", "the backend server of app", cliOpts)
cmdDB = cmdMain.SubCommand("db", "database operations")
)
10 months ago
3 weeks ago
func init() {
10 months ago
cmdMain.Command = runWeb
10 months ago
cmdDB.SubCommand("migrate", "migrate database").Command = models.Migrate
cmdDB.SubCommand("drop", "drop database").Command = models.Drop
10 months ago
cmdDB.SubCommand("init", "init db data").Command = models.InitDB
10 months ago
}
func main() {
10 months ago
cmdMain.Parse()
err := cmdMain.Run()
11 months ago
if err != nil {
logv.Warn().Msg(err.Error())
}
}
func runWeb() error {
server, err := vigo.New(vigo.WithHost(cliOpts.Host), vigo.WithPort(cliOpts.Port))
11 months ago
if err != nil {
return err
}
3 weeks ago
server.SetRouter(vbase.Router)
11 months ago
return server.Run()
}