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/sub/web.go

50 lines
1.1 KiB
Go

3 years ago
package sub
import (
"github.com/urfave/cli/v2"
"github.com/veypi/OneAuth/api"
"github.com/veypi/OneAuth/cfg"
3 years ago
"github.com/veypi/OneBD"
"github.com/veypi/utils/log"
)
// go:embed static/static
//var staticFiles embed.FS
3 years ago
// go:embed static/favicon.ico
//var icon []byte
3 years ago
// go:embed static/index.html
//var indexFile []byte
3 years ago
var Web = &cli.Command{
3 years ago
Name: "web",
Usage: "",
Description: "oa 核心http服务",
Action: RunWeb,
Flags: []cli.Flag{},
}
func RunWeb(c *cli.Context) error {
ll := log.InfoLevel
if l, err := log.ParseLevel(cfg.CFG.LoggerLevel); err == nil {
ll = l
}
app := OneBD.New(&OneBD.Config{
Host: cfg.CFG.Host,
LoggerPath: cfg.CFG.LoggerPath,
LoggerLevel: ll,
})
api.Router(app.Router().SubRouter("api"))
3 years ago
// TODO media 文件需要检验权限
app.Router().SubRouter("/media/").Static("/", cfg.CFG.MediaDir)
//app.Router().EmbedDir("/static", staticFiles, "static/static/")
//app.Router().EmbedFile("/favicon.ico", icon)
//app.Router().EmbedFile("/*", indexFile)
3 years ago
3 years ago
log.Info().Msg("\nRouting Table\n" + app.Router().String())
return app.Run()
}