working commit
This commit is contained in:
@@ -4,20 +4,47 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mbase/pkg/client"
|
||||
"mbase/pkg/mbctl"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
//util.createAccountParams.Filename = args[0]
|
||||
util.createAccountParams.Username = args[0]
|
||||
util.createAccountParams.Password = args[1]
|
||||
res, err := util.createAccount(util.createAccountParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createAccountParams struct{}
|
||||
type createAccountResult struct{}
|
||||
type CreateAccountParams struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
type CreateAccountResult struct {
|
||||
AccountID string
|
||||
}
|
||||
|
||||
func (util *Util) createAccount(params createAccountParams) (createAccountResult, error) {
|
||||
func (util *Util) createAccount(params CreateAccountParams) (CreateAccountResult, error) {
|
||||
var err error
|
||||
res := createAccountResult{}
|
||||
res := CreateAccountResult{}
|
||||
|
||||
grpcConn, cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer grpcConn.Close()
|
||||
operParams := &mbctl.CreateAccountParams{
|
||||
Username: params.Username,
|
||||
Password: params.Password,
|
||||
}
|
||||
ctx := context.Background()
|
||||
operRes, err := cli.CreateAccount(ctx, operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.AccountID = operRes.AccountID
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user