Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AddCmd = &cobra.Command{ Use: "add", Short: "add admin by user id", Long: `add admin by user id`, PreRunE: func(cmd *cobra.Command, args []string) error { return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add( bootstrap.InitDiscardLog, bootstrap.InitConfig, bootstrap.InitDatabase, ).Run() }, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("missing user id") } u, err := db.GetUserByID(args[0]) if err != nil { fmt.Printf("get user failed: %s", err) return nil } if err := db.AddAdmin(u); err != nil { fmt.Printf("add admin failed: %s", err) return nil } fmt.Printf("add admin success: %s\n", u.Username) return nil }, }
View Source
var AdminCmd = &cobra.Command{
Use: "admin",
Short: "admin",
Long: `you must first shut down the server, otherwise the changes will not take effect.`,
}
View Source
var RemoveCmd = &cobra.Command{ Use: "remove", Short: "remove", Long: `remove admin`, PreRunE: func(cmd *cobra.Command, args []string) error { return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add( bootstrap.InitDiscardLog, bootstrap.InitConfig, bootstrap.InitDatabase, ).Run() }, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("missing user id") } u, err := db.GetUserByID(args[0]) if err != nil { fmt.Printf("get user failed: %s", err) return nil } if err := db.RemoveAdmin(u); err != nil { fmt.Printf("remove admin failed: %s", err) return nil } fmt.Printf("remove admin success: %s\n", u.Username) return nil }, }
View Source
var ShowCmd = &cobra.Command{ Use: "show", Short: "show admin", Long: `show admin`, PreRunE: func(cmd *cobra.Command, args []string) error { return bootstrap.New(bootstrap.WithContext(cmd.Context())).Add( bootstrap.InitDiscardLog, bootstrap.InitConfig, bootstrap.InitDatabase, ).Run() }, RunE: func(cmd *cobra.Command, args []string) error { admins, err := db.GetAdmins() if err != nil { fmt.Printf("get admins failed: %s\n", err.Error()) } for _, admin := range admins { fmt.Printf("id: %s\tusername: %s\n", admin.ID, admin.Username) } return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.