working commit
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"mbase/app/logic"
|
||||
"mbase/app/operator"
|
||||
"mbase/pkg/logger"
|
||||
"mbase/pkg/mbctl"
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
type HandlerConfig struct {
|
||||
Logic *logic.Logic
|
||||
Logic *operator.Logic
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
mbctl.UnimplementedControlServer
|
||||
lg *logic.Logic
|
||||
lg *operator.Logic
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package logic
|
||||
package operator
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"mbase/app/config"
|
||||
"mbase/app/maindb"
|
||||
"mbase/pkg/descr"
|
||||
"mbase/app/logic"
|
||||
"mbase/app/operator"
|
||||
"mbase/pkg/aux509"
|
||||
"mbase/pkg/logger"
|
||||
"mbase/pkg/netacl"
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
type Server struct {
|
||||
conf *config.Config
|
||||
lg *logic.Logic
|
||||
lg *operator.Logic
|
||||
svc *service.Service
|
||||
hand *handler.Handler
|
||||
log *logger.Logger
|
||||
@@ -176,10 +176,10 @@ func (srv *Server) Build() error {
|
||||
return err
|
||||
}
|
||||
// Create logic
|
||||
logicConfig := &logic.LogicConfig{
|
||||
logicConfig := &operator.LogicConfig{
|
||||
Database: srv.db,
|
||||
}
|
||||
srv.lg, err = logic.NewLogic(logicConfig)
|
||||
srv.lg, err = operator.NewLogic(logicConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"net"
|
||||
|
||||
"mbase/app/handler"
|
||||
"mbase/app/logic"
|
||||
"mbase/app/operator"
|
||||
"mbase/pkg/logger"
|
||||
"mbase/pkg/netacl"
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
type ServiceConfig struct {
|
||||
Handler *handler.Handler
|
||||
Logic *logic.Logic
|
||||
Logic *operator.Logic
|
||||
NetACL *netacl.NetACL
|
||||
Portnum uint32
|
||||
Address string
|
||||
@@ -33,7 +33,7 @@ type ServiceConfig struct {
|
||||
type Service struct {
|
||||
gsrv *grpc.Server
|
||||
hand *handler.Handler
|
||||
lg *logic.Logic
|
||||
lg *operator.Logic
|
||||
log *logger.Logger
|
||||
nacl *netacl.NetACL
|
||||
portnum uint32
|
||||
|
||||
@@ -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