working commit
This commit is contained in:
@@ -13,11 +13,40 @@ func (util *Util) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createAccountParams struct{}
|
||||
type createAccountParams struct{
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
type createAccountResult struct{}
|
||||
|
||||
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
||||
var err error
|
||||
res := createAccountResult{}
|
||||
/*
|
||||
operParams := &mbctl.CreateAccountParams{
|
||||
Username: params.Username,
|
||||
Password: params.Password,
|
||||
}
|
||||
res, err = util.lg.CreateAccount(ctx, operID, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
*/
|
||||
return res, err
|
||||
}
|
||||
/*
|
||||
func (util *Util) CreateAccount(ctx context.Context, operID string) (*mbctl.CreateAccountResult, error) {
|
||||
var err error
|
||||
res := &mbctl.CreateAccountResult{}
|
||||
|
||||
params := &mbctl.CreateAccountParams{
|
||||
Username: util.username,
|
||||
Password: util.password,
|
||||
}
|
||||
res, err = util.lg.CreateAccount(ctx, operID, params)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"mbase/app/operator"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
oper *operator.Logic
|
||||
rootCmd *cobra.Command
|
||||
createAccountParams createAccountParams
|
||||
listAccountsParams listAccountsParams
|
||||
@@ -15,8 +18,10 @@ type Util struct {
|
||||
deleteAccountParams deleteAccountParams
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
return &Util{}
|
||||
func NewUtil(oper *operator.Logic) *Util {
|
||||
return &Util{
|
||||
oper: oper,
|
||||
}
|
||||
}
|
||||
|
||||
func (util *Util) GetRooCmd() *cobra.Command {
|
||||
@@ -65,4 +70,3 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
util.rootCmd = rootCmd
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
|
||||
+36
-1
@@ -8,11 +8,17 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"mbase/cmd/mbaseadmin/account"
|
||||
"mbase/app/config"
|
||||
"mbase/app/maindb"
|
||||
"mbase/app/operator"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Util struct {
|
||||
lg *operator.Logic
|
||||
db *maindb.Database
|
||||
|
||||
rootCmd *cobra.Command
|
||||
}
|
||||
|
||||
@@ -26,6 +32,34 @@ func (util *Util) GetRooCmd() *cobra.Command {
|
||||
|
||||
func (util *Util) Build() error {
|
||||
var err error
|
||||
|
||||
conf := config.NewConfig()
|
||||
err = conf.ReadFile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = conf.ReadEnv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db, err := maindb.NewDatabase(conf.DataDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.OpenDatabase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
util.db = db
|
||||
logicConfig := &operator.LogicConfig{
|
||||
Database: util.db,
|
||||
}
|
||||
util.lg, err = operator.NewLogic(logicConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
execName := filepath.Base(os.Args[0])
|
||||
rootCmd := &cobra.Command{
|
||||
Use: execName,
|
||||
@@ -34,7 +68,7 @@ func (util *Util) Build() error {
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
accountUtil := account.NewUtil()
|
||||
accountUtil := account.NewUtil(util.lg)
|
||||
rootCmd.AddCommand(accountUtil.BuildCmds())
|
||||
|
||||
util.rootCmd = rootCmd
|
||||
@@ -47,3 +81,4 @@ func (util *Util) Exec(args []string) error {
|
||||
err = util.rootCmd.Execute()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user