aboutsummaryrefslogtreecommitdiff
path: root/app/cmd/user.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:47:35 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:47:35 +0300
commit96e2ce2e9d363a6296f9411ecb00168520258874 (patch)
tree09aa7fffe10eab84ae0edd39e570355984ba0148 /app/cmd/user.go
parent12ed72e4e1da181a6c87319a50d3b4142788b4c0 (diff)
Отказ от echo
Diffstat (limited to 'app/cmd/user.go')
-rw-r--r--app/cmd/user.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/app/cmd/user.go b/app/cmd/user.go
index 673c7b8..1f88c6f 100644
--- a/app/cmd/user.go
+++ b/app/cmd/user.go
@@ -6,9 +6,9 @@ import (
"os"
"github.com/spf13/cobra"
- "gitrepo.ru/neonxp/gorum/db"
"gitrepo.ru/neonxp/gorum/models"
"gitrepo.ru/neonxp/gorum/repository"
+ "go.etcd.io/bbolt"
)
var userCmd = &cobra.Command{
@@ -21,7 +21,7 @@ var createUserCmd = &cobra.Command{
Args: cobra.ExactArgs(3),
ArgAliases: []string{"username", "email", "role"},
RunE: func(cmd *cobra.Command, args []string) error {
- orm, err := db.GetDB(dbFile)
+ orm, err := bbolt.Open(dbFile, 0600, nil)
if err != nil {
return fmt.Errorf("failed init db: %w", err)
}
@@ -40,12 +40,11 @@ var createUserCmd = &cobra.Command{
password, _ := reader.ReadString('\n')
ur := repository.NewUser(orm)
- id, err := ur.Create(cmd.Context(), email, password, username, iRole)
- if err != nil {
+ if err := ur.Create(email, password, username, iRole); err != nil {
return fmt.Errorf("failed create user: %w", err)
}
- fmt.Printf("Created user %s (id=%d, email=%s, role_id=%d)\n", username, id, email, iRole)
+ fmt.Printf("Created user %s (email=%s, role_id=%d)\n", username, email, iRole)
return nil
},
@@ -54,20 +53,20 @@ var createUserCmd = &cobra.Command{
var listUserCmd = &cobra.Command{
Use: "list",
RunE: func(cmd *cobra.Command, args []string) error {
- orm, err := db.GetDB(dbFile)
+ orm, err := bbolt.Open(dbFile, 0600, nil)
if err != nil {
return fmt.Errorf("failed init db: %w", err)
}
ur := repository.NewUser(orm)
- users, err := ur.List(cmd.Context())
+ users, err := ur.List()
if err != nil {
return err
}
- fmt.Printf("ID\tUsername\tEmail\tRole\n")
+ fmt.Printf("Username\tEmail\tRole\n")
for _, u := range users {
- fmt.Printf("%d\t%s\t%s\t%d\n", u.ID, u.Username, u.Email, u.Role)
+ fmt.Printf("%s\t%s\t%d\n", u.Username, u.Email, u.Role)
}
return nil