paisa/cmd/serve.go

36 lines
920 B
Go
Raw Normal View History

2022-03-30 12:11:44 -04:00
package cmd
import (
mutualfund "github.com/ananthakumaran/paisa/internal/model/mutualfund/scheme"
nps "github.com/ananthakumaran/paisa/internal/model/nps/scheme"
"github.com/ananthakumaran/paisa/internal/model/posting"
"github.com/ananthakumaran/paisa/internal/model/price"
2022-03-30 12:11:44 -04:00
"github.com/ananthakumaran/paisa/internal/server"
2022-04-02 03:31:29 -04:00
log "github.com/sirupsen/logrus"
2022-03-30 12:11:44 -04:00
"github.com/spf13/cobra"
2022-04-02 03:31:29 -04:00
"github.com/spf13/viper"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
2022-03-30 12:11:44 -04:00
)
var serveCmd = &cobra.Command{
Use: "serve",
Short: "serve the WEB UI",
Run: func(cmd *cobra.Command, args []string) {
2022-04-02 03:31:29 -04:00
db, err := gorm.Open(sqlite.Open(viper.GetString("db_path")), &gorm.Config{})
db.AutoMigrate(&nps.Scheme{})
db.AutoMigrate(&mutualfund.Scheme{})
db.AutoMigrate(&posting.Posting{})
db.AutoMigrate(&price.Price{})
2022-04-02 03:31:29 -04:00
if err != nil {
log.Fatal(err)
}
server.Listen(db)
2022-03-30 12:11:44 -04:00
},
}
func init() {
rootCmd.AddCommand(serveCmd)
}