This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/cmd/cmd.go
2021-01-11 23:48:32 -05:00

88 lines
2.3 KiB
Go

package cmd
import (
"reichard.io/imagini/routes"
"reichard.io/imagini/internal/context"
"github.com/urfave/cli/v2"
"net/http"
log "github.com/sirupsen/logrus"
)
var CmdServe = cli.Command{
Name: "serve",
Aliases: []string{"s"},
Usage: "Start Imagini web server.",
Action: serveWeb,
}
// var CmdDBTest = cli.Command{
// Name: "test",
// Aliases: []string{"t"},
// Usage: "test db.",
// Action: testDatabase,
// }
func serveWeb(cliCtx *cli.Context) error {
log.Info("Serving Web")
ctx := context.NewImaginiContext()
routes.RegisterRoutes(ctx)
//listener, _ := net.Listen("tcp", ctx.Config.ListenPort)
if err := http.ListenAndServe(":" + ctx.Config.ListenPort, nil); err != nil {
log.Fatal(err)
}
return nil
}
// func testDatabase(cliCtx *cli.Context) error {
// log.Info("Testing Database")
// c := config.NewConfig()
// db.ConnectDB(c)
//
// err := auth.CreateUser(models.User{
// Username: "User123",
// Email: "user26@evan.pub",
// FirstName: "User",
// LastName: "Reichard",
// AuthType: "Local",
// }, "myPassword123")
//
// if err != nil {
// fmt.Println(err)
// }
//
// resp := auth.AuthenticateUser(models.APICredentials{User:"User123", Password: "myPassword123"})
// if resp == true {
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY USERNAME")
// }else {
// log.Info("USER NOT AUTHENTICATED")
// }
//
// resp = auth.AuthenticateUser(models.APICredentials{User:"user26@evan.pub", Password: "myPassword123"})
// if resp == true {
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
// }else {
// log.Info("USER NOT AUTHENTICATED")
// }
//
// resp = auth.AuthenticateUser(models.APICredentials{User:"user@evan.pub", Password: "myPassword12"})
// if resp == true {
// log.Info("USER SUCCESSFULLY AUTHENTICATED BY EMAIL")
// }else {
// log.Info("USER NOT AUTHENTICATED")
// }
//
// // foundUser, err := db.GetUser(db.User{Username: "User123"})
//
// // if errors.Is(err, gorm.ErrRecordNotFound) {
// // log.Warn("RECORD NOT FOUND")
// // } else {
// // log.Info("FOUND USER", foundUser)
// // }
//
// return nil
// }