feat: connect to db
This commit is contained in:
@@ -1,39 +1,43 @@
|
||||
/*
|
||||
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/pkg/middlewares/fiberv3"
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/pkg/wechat"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"log"
|
||||
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/cmd"
|
||||
"git.ipao.vip/rogeecn/mp-qvyun/conf"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
func main() {
|
||||
wechatClient := wechat.New(
|
||||
wechat.WithAppID(WechatAppID),
|
||||
wechat.WithAppSecret(WechatAppSecret),
|
||||
wechat.WithAESKey(WechatAesKey),
|
||||
wechat.WithToken(WechatToken),
|
||||
)
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "qvyun",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := conf.Load(cmd.Flag("config").Value.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wechatMiddlewares := fiberv3.Init(wechatClient)
|
||||
if cmd.Flag("debug").Value.String() == "true" {
|
||||
conf.C.Debug = true
|
||||
}
|
||||
|
||||
// create a new fiber server
|
||||
app := fiber.New()
|
||||
app.Use(LogAll)
|
||||
app.Use(wechatMiddlewares.Verify)
|
||||
app.Use(wechatMiddlewares.AuthUserInfo)
|
||||
app.Use(wechatMiddlewares.SilentAuth)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
app.Get("/", func(c fiber.Ctx) error {
|
||||
return c.SendString("Hello World")
|
||||
})
|
||||
rootCmd.PersistentFlags().StringP("config", "C", "", "config file")
|
||||
rootCmd.PersistentFlags().BoolP("debug", "D", false, "debug mode")
|
||||
|
||||
// listen on port 3000
|
||||
if err := app.Listen(":3000"); err != nil {
|
||||
cmd.CommandServe(rootCmd)
|
||||
cmd.CommandMigrate(rootCmd)
|
||||
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user