diff --git a/Client b/Client new file mode 100755 index 0000000..18ce951 Binary files /dev/null and b/Client differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02a659b --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +all: + go build ./src/Server/Server.go + go build ./src/Client/Client.go + +clean: + rm -f ./Server ./Client + diff --git a/Server b/Server new file mode 100755 index 0000000..ac79398 Binary files /dev/null and b/Server differ diff --git a/docs/assets/ClassDiagram Client.svg b/docs/assets/ClassDiagram Client.svg new file mode 100644 index 0000000..2f6f451 --- /dev/null +++ b/docs/assets/ClassDiagram Client.svg @@ -0,0 +1,3 @@ + + +
Utiliza para comunicação RPC
Usa callbacks de BankBranch
Usa callbacks de ATM
Client
+Call(serverAddress string, serverPort int, callback func(*rpc.Client) error)
BankBranch
+OpenNewAccount(name string, password string) func(*rpc.Client) : error
+CloseAccount(id int64, password string) func(*rpc.Client) : error
+Withdraw(id int64, password string, quantity float64) func(*rpc.Client) : error
+Deposit(id int64, password string, quantity float64) func(*rpc.Client) : error
+CheckBalance(id int64, password string) func(*rpc.Client) : error
ATM
+Withdraw(id int64, password string, quantity float64) func(*rpc.Client) : error
+Deposit(id int64, password string, quantity float64) func(*rpc.Client) : error
+CheckBalance(id int64, password string) func(*rpc.Client) : error
«external»
rpc.Client
\ No newline at end of file diff --git a/docs/assets/ClassDiagram Server.svg b/docs/assets/ClassDiagram Server.svg new file mode 100644 index 0000000..7e8b6c0 --- /dev/null +++ b/docs/assets/ClassDiagram Server.svg @@ -0,0 +1,3 @@ + + +
"manages"
"uses for input"
"uses for input"
"uses for input"
Bank
-accounts map[int64]*account
-nextID int64
-mutex sync.RWMutex
+Initialize()
+OpenAccount(accountName string, accountPassword string, result *int64) : error
+CloseAccount(accountID int64, accountPassword string, result *bool) : error
+Withdraw(accountID int64, accountPassword string, quantity float64, result *bool) : error
+Deposit(accountID int64, accountPassword string, quantity float64, result *bool) : error
+PeekBalance(accountID int64, accountPassword string, result *float64) : error
account
-Name string
-Password string
-Balance float64
-mutex sync.RWMutex
OpenAccountRequest
+Name string
+Password string
AccountAccessRequest
+ID int64
+Password string
FundsOperationRequest
+ID int64
+Password string
+Quantity float64
\ No newline at end of file diff --git a/docs/assets/SequenceDiagram 1.svg b/docs/assets/SequenceDiagram 1.svg new file mode 100644 index 0000000..92dce75 --- /dev/null +++ b/docs/assets/SequenceDiagram 1.svg @@ -0,0 +1,3 @@ + + +BankServerClientBankBranchBankServerClientBankBranchSolicitação de operação (e.g., OpenNewAccount)Prepara requisição RPCEnvia requisição RPC (e.g., Bank.OpenAccount)Processa a requisição (e.g., OpenAccount)Retorna resposta (e.g., ID da conta)Envia resposta RPCRetorna resultado da operaçãoExibe resultado \ No newline at end of file diff --git a/docs/assets/SequenceDiagram 2.svg b/docs/assets/SequenceDiagram 2.svg new file mode 100644 index 0000000..fe566c4 --- /dev/null +++ b/docs/assets/SequenceDiagram 2.svg @@ -0,0 +1,3 @@ + + +BankServerClientBankBranchATMBankServerClientBankBranchATMSolicitação de operação (e.g., CheckBalance)Prepara requisição RPCEnvia requisição RPC (e.g., Bank.PeekBalance)Processa a requisição (e.g., PeekBalance)Retorna resposta (e.g., Saldo da conta)Envia resposta RPCRetorna resultado da operaçãoExibe resultadoSolicitação de operação (e.g., Withdraw)Prepara requisição RPCEnvia requisição RPC (e.g., Bank.Withdraw)Processa a requisição (e.g., Withdraw)Retorna resposta (e.g., Sucesso/Falha)Envia resposta RPCRetorna resultado da operaçãoExibe resultado \ No newline at end of file diff --git a/src/settings.yml b/settings.yml similarity index 100% rename from src/settings.yml rename to settings.yml diff --git a/src/Client/ATM/ATM.go b/src/Client/ATM/ATM.go index 02e7f12..e97d815 100644 --- a/src/Client/ATM/ATM.go +++ b/src/Client/ATM/ATM.go @@ -6,17 +6,17 @@ import ( ) type AccountAccessRequest struct { - ID int64 + ID int Password string } type FundsOperationRequest struct { - ID int64 + ID int Password string Quantity float64 } -func Withdraw(id int64, password string, quantity float64) func(*rpc.Client) error { +func Withdraw(id int, password string, quantity float64) func(*rpc.Client) error { return func(client *rpc.Client) error { request := FundsOperationRequest{id, password, quantity} @@ -31,7 +31,7 @@ func Withdraw(id int64, password string, quantity float64) func(*rpc.Client) err } } -func Deposit(id int64, password string, quantity float64) func(*rpc.Client) error { +func Deposit(id int, password string, quantity float64) func(*rpc.Client) error { return func(client *rpc.Client) error { request := FundsOperationRequest{id, password, quantity} @@ -46,7 +46,7 @@ func Deposit(id int64, password string, quantity float64) func(*rpc.Client) erro } } -func CheckBalance(id int64, password string) func(*rpc.Client) error { +func CheckBalance(id int, password string) func(*rpc.Client) error { return func(client *rpc.Client) error { request := AccountAccessRequest{id, password} diff --git a/src/Client/BankBranch/BankBranch.go b/src/Client/BankBranch/BankBranch.go index c182e0d..581054e 100644 --- a/src/Client/BankBranch/BankBranch.go +++ b/src/Client/BankBranch/BankBranch.go @@ -11,12 +11,12 @@ type OpenAccountRequest struct { } type AccountAccessRequest struct { - ID int64 + ID int Password string } type FundsOperationRequest struct { - ID int64 + ID int Password string Quantity float64 } @@ -25,7 +25,7 @@ func OpenNewAccount(name string, password string) func(*rpc.Client) error { return func(client *rpc.Client) error { request := OpenAccountRequest{name, password} - var response int64 + var response int err := client.Call("Bank.OpenAccount", request, &response) if err != nil { @@ -36,7 +36,7 @@ func OpenNewAccount(name string, password string) func(*rpc.Client) error { } } -func CloseAccount(id int64, password string) func(*rpc.Client) error { +func CloseAccount(id int, password string) func(*rpc.Client) error { return func(client *rpc.Client) error { request := AccountAccessRequest{id, password} @@ -51,7 +51,7 @@ func CloseAccount(id int64, password string) func(*rpc.Client) error { } } -func Withdraw(id int64, password string, quantity float64) func(*rpc.Client) error { +func Withdraw(id int, password string, quantity float64) func(*rpc.Client) error { return func(client *rpc.Client) error { request := FundsOperationRequest{id, password, quantity} @@ -66,7 +66,7 @@ func Withdraw(id int64, password string, quantity float64) func(*rpc.Client) err } } -func Deposit(id int64, password string, quantity float64) func(*rpc.Client) error { +func Deposit(id int, password string, quantity float64) func(*rpc.Client) error { return func(client *rpc.Client) error { request := FundsOperationRequest{id, password, quantity} @@ -81,7 +81,7 @@ func Deposit(id int64, password string, quantity float64) func(*rpc.Client) erro } } -func CheckBalance(id int64, password string) func(*rpc.Client) error { +func CheckBalance(id int, password string) func(*rpc.Client) error { return func(client *rpc.Client) error { request := AccountAccessRequest{id, password} diff --git a/src/Client/Client.go b/src/Client/Client.go index 1c67424..f13e518 100644 --- a/src/Client/Client.go +++ b/src/Client/Client.go @@ -1,10 +1,31 @@ -package Client +package main import ( + "Coinnect-FPPD/src/Menu" + Pygmalion "Coinnect-FPPD/src/deps" "fmt" "net/rpc" ) +func main() { + // Carrega configurações + Pygmalion.InitConfigReader("settings.yml", ".") + port := Pygmalion.ReadInteger("ServerPort") + address := Pygmalion.ReadString("ServerAddr") + fmt.Printf("Client.main : Initializing Client : ServerAddress=%s, ServerPort=%d\n", address, port) + + for { + // Executa uma operação + callback := Menu.ObtainClientOperation() + if callback != nil { + // Executa a chamada ao servidor + SendOperation(address, port, callback) + continue + } + break + } +} + func SendOperation(serverAddress string, serverPort int, callback func(*rpc.Client) error) { // Tenta uma conexão TCP com o banco client, err := rpc.Dial("tcp", fmt.Sprintf("%s:%d", serverAddress, serverPort)) diff --git a/src/Menu/Menu.go b/src/Menu/Menu.go index 9127493..d8215c6 100644 --- a/src/Menu/Menu.go +++ b/src/Menu/Menu.go @@ -5,19 +5,39 @@ import ( "Coinnect-FPPD/src/Client/BankBranch" "fmt" "net/rpc" - "os" + "strconv" ) -func ObtainClientOperation() func(*rpc.Client) error { +// Constantes para melhorar a leitura dos switch cases +type MenuChoice int + +const ( + Exit MenuChoice = iota + GoToATM + GoToBankBranch +) + +type OperationChoice int - // Menu principal +const ( + Return OperationChoice = iota + CheckBalance + Deposit + Withdraw + OpenAccount + CloseAccount +) + +// Menu principal +func ObtainClientOperation() func(*rpc.Client) error { for { + fmt.Println("\n--- Menu Principal ---") fmt.Println("\nEscolha uma opção:") fmt.Println("1. Utilizar ATM") fmt.Println("2. Ir a um BankBranch") fmt.Println("3. Sair") - var choice int + var choice MenuChoice fmt.Print("Digite sua escolha: ") _, err := fmt.Scanln(&choice) if err != nil { @@ -26,36 +46,35 @@ func ObtainClientOperation() func(*rpc.Client) error { } switch choice { - case 1: - operation := menuATM() + case Exit: + fmt.Println("Encerrando o programa.") + return nil + case GoToATM: + operation := presentATMMenu() if operation != nil { return operation } - case 2: - operation := menuBankBranch() + case GoToBankBranch: + operation := presentBankBranchMenu() // Vai retornar nil caso o cliente queira voltar ao menu principal if operation != nil { return operation } - - case 3: - fmt.Println("Encerrando o programa.") - os.Exit(1) default: - fmt.Println("Escolha inválida. Tente novamente.") + fmt.Println("Escolha inválida. Tente novamente") } } } -func menuATM() func(*rpc.Client) error { +func presentATMMenu() func(*rpc.Client) error { for { fmt.Println("\n--- Menu ATM ---") + fmt.Println("0. Voltar ao menu principal") fmt.Println("1. Consultar saldo") fmt.Println("2. Depositar") fmt.Println("3. Retirar") - fmt.Println("4. Voltar ao menu principal") - var choice int + var choice OperationChoice fmt.Print("Digite sua escolha: ") _, err := fmt.Scanln(&choice) if err != nil { @@ -64,55 +83,34 @@ func menuATM() func(*rpc.Client) error { } switch choice { - case 1: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) + case Return: + return nil + case CheckBalance: + id, password := getIDPasswordInput() return ATM.CheckBalance(id, password) - case 2: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) - fmt.Print("Digite o valor a depositar: ") - var amount float64 - fmt.Scanln(&amount) + case Deposit: + id, password, amount := getIDPasswordAmountInput("depositar") return ATM.Deposit(id, password, amount) - case 3: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) - fmt.Print("Digite o valor a retirar: ") - var amount float64 - fmt.Scanln(&amount) + case Withdraw: + id, password, amount := getIDPasswordAmountInput("retirar") return ATM.Withdraw(id, password, amount) - case 4: - return nil default: fmt.Println("Escolha inválida. Tente novamente.") } } } -func menuBankBranch() func(*rpc.Client) error { +func presentBankBranchMenu() func(*rpc.Client) error { for { fmt.Println("\n--- Menu BankBranch ---") + fmt.Println("0. Voltar ao menu principal") fmt.Println("1. Consultar saldo") fmt.Println("2. Depositar") fmt.Println("3. Retirar") fmt.Println("4. Abrir nova conta") fmt.Println("5. Fechar conta") - fmt.Println("6. Voltar ao menu principal") - var choice int + var choice OperationChoice fmt.Print("Digite sua escolha: ") _, err := fmt.Scanln(&choice) if err != nil { @@ -121,56 +119,65 @@ func menuBankBranch() func(*rpc.Client) error { } switch choice { - case 1: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) + case Return: + return nil + case CheckBalance: + id, password := getIDPasswordInput() return BankBranch.CheckBalance(id, password) - case 2: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) - fmt.Print("Digite o valor a depositar: ") - var amount float64 - fmt.Scanln(&amount) + case Deposit: + id, password, amount := getIDPasswordAmountInput("depositar") return BankBranch.Deposit(id, password, amount) - case 3: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) - fmt.Print("Digite o valor a retirar: ") - var amount float64 - fmt.Scanln(&amount) + case Withdraw: + id, password, amount := getIDPasswordAmountInput("") return BankBranch.Withdraw(id, password, amount) - case 4: - fmt.Print("Digite o nome da nova conta: ") - var name string - fmt.Scanln(&name) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) + case OpenAccount: + name, password := getNamePasswordInput() return BankBranch.OpenNewAccount(name, password) - case 5: - fmt.Print("Digite o ID da conta: ") - var id int64 - fmt.Scanln(&id) - fmt.Print("Digite a senha: ") - var password string - fmt.Scanln(&password) + case CloseAccount: + id, password := getIDPasswordInput() return BankBranch.CloseAccount(id, password) - case 6: - return nil default: fmt.Println("Escolha inválida. Tente novamente.") } } } + +func getNamePasswordInput() (string, string) { + fmt.Print("Digite o nome da nova conta: ") + var name string + fmt.Scanln(&name) + + fmt.Print("Digite a senha: ") + var password string + fmt.Scanln(&password) + + return name, password +} + +func getIDPasswordInput() (int, string) { + fmt.Print("Digite o ID da conta: ") + var stringId string + var password string + + _, err := fmt.Scanln(&stringId) + if err != nil { + fmt.Println("Erro ao ler o ID da conta. Certifique-se de inserir um número válido.") + } + + fmt.Print("Digite a senha: ") + fmt.Scanln(&password) + + id, _ := strconv.Atoi(stringId) + fmt.Printf("ClientID: %d ClientPasswort:%s\n", id, password) + return id, password +} + +func getIDPasswordAmountInput(operation string) (int, string, float64) { + id, password := getIDPasswordInput() + + fmt.Printf("Digite o valor a %s: ", operation) + var amount float64 + fmt.Scanln(&amount) + + return id, password, amount +} diff --git a/src/Server/Bank/Bank.go b/src/Server/Bank/Bank.go index 1ae42f9..679bcc9 100644 --- a/src/Server/Bank/Bank.go +++ b/src/Server/Bank/Bank.go @@ -5,6 +5,23 @@ import ( "sync" ) +// Estruturas auxiliares para requests de login e operações. +type OpenAccountRequest struct { + Name string + Password string +} + +type AccountAccessRequest struct { + AccountID int + Password string +} + +type FundsOperationRequest struct { + AccountID int + Password string + Quantity float64 +} + // account representa uma conta bancária com nome, senha e saldo. type account struct { Name string // Nome do titular da conta. @@ -13,31 +30,20 @@ type account struct { mutex sync.RWMutex // RWMutex para operações seguras em nível de conta. } -// Estruturas auxiliares para requests de login e operações. -type LoginRequest struct { - AccountID string - AccountPassword string -} - -type OperationRequest struct { - AccountID string - AccountPassword string - Quantity float64 -} - // Bank representa um banco que gerencia múltiplas contas. type Bank struct { - accounts map[int64]*account // Mapeia cada ID de conta para os dados da conta. - nextID int64 // ID da próxima conta a ser criada. - mutex sync.RWMutex // RWMutex para garantir segurança em operações concorrentes em nível de banco. + accounts map[int]*account // Mapeia cada ID de conta para os dados da conta. + nextID int // ID da próxima conta a ser criada. + mutex sync.RWMutex // RWMutex para garantir segurança em operações concorrentes em nível de banco. } // Initialize configura o banco inicializando o map de contas e criando uma conta de teste. func (b *Bank) Initialize() { + fmt.Println("BankManager.Initialize : Initializing bank.") b.mutex.Lock() defer b.mutex.Unlock() - b.accounts = make(map[int64]*account) + b.accounts = make(map[int]*account) b.nextID = 1 // Conta hardcoded para teste @@ -47,92 +53,102 @@ func (b *Bank) Initialize() { Balance: 2000, } b.nextID++ + fmt.Printf("BankManager.Initialize : Finished initializing : Next usable ID=%d\n", b.nextID) } // OpenAccount cria uma nova conta bancária com o nome e a senha fornecidos. -func (b *Bank) OpenAccount(accountName string, accountPassword string, result *int64) error { +func (b *Bank) OpenAccount(request OpenAccountRequest, result *int) error { b.mutex.Lock() defer b.mutex.Unlock() - + fmt.Printf("BankManager.OpenAccount : Opening a new account : AccountID=%d : Name=%s\n", b.nextID, request.Name) b.accounts[b.nextID] = &account{ - Name: accountName, - Password: accountPassword, + Name: request.Name, + Password: request.Password, Balance: 0, } *result = b.nextID b.nextID++ + fmt.Printf("BankManager.OpenAccount : Opened a new account successfully : Next Usable ID=%d\n", b.nextID) return nil } // CloseAccount fecha a conta com o ID fornecido, após autenticação da senha. -func (b *Bank) CloseAccount(accountID int64, accountPassword string, result *bool) error { - _, isAuthenticated := b.getAuthenticatedAccount(accountID, accountPassword) +func (b *Bank) CloseAccount(request AccountAccessRequest, result *bool) error { + account, isAuthenticated := b.getAuthenticatedAccount(request.AccountID, request.Password) if isAuthenticated { b.mutex.Lock() defer b.mutex.Unlock() - delete(b.accounts, accountID) + fmt.Printf("BankManager.CloseAccount : Closing account : AccountID=%d : Balance=%.2f : ClientName=%s\n", request.AccountID, account.Balance, account.Name) + delete(b.accounts, request.AccountID) *result = true return nil } *result = false - return fmt.Errorf("BankManager.CloseAccount : Failed to authenticate account : AccountID=%d", accountID) + fmt.Printf("BankManager.CloseAccount : Failed to authenticate account : AccountID=%d : AccountPassword=%s\n", request.AccountID, request.Password) + return fmt.Errorf("BankManager.CloseAccount : Failed to authenticate account : AccountID=%d", request.AccountID) } // Withdraw realiza um saque de uma conta especificada, caso haja saldo suficiente. -func (b *Bank) Withdraw(accountID int64, accountPassword string, quantity float64, result *bool) error { - account, isAuthenticated := b.getAuthenticatedAccount(accountID, accountPassword) +func (b *Bank) Withdraw(request FundsOperationRequest, result *bool) error { + account, isAuthenticated := b.getAuthenticatedAccount(request.AccountID, request.Password) if isAuthenticated { account.mutex.Lock() defer account.mutex.Unlock() - if account.Balance >= quantity { - account.Balance -= quantity + if account.Balance >= request.Quantity { + account.Balance -= request.Quantity *result = true + fmt.Printf("BankManager.Withdraw : Withdrawing funds : AccountID=%d : Balance=%.2f : Quantity=%.2f\n", request.AccountID, account.Balance, request.Quantity) return nil } *result = false - return fmt.Errorf("BankManager.Withdraw : Insufficient funds for account : AccountID=%d", accountID) + return fmt.Errorf("BankManager.Withdraw : Insufficient funds for account : AccountID=%d : Quantity=%.2f", request.AccountID, request.Quantity) } *result = false - return fmt.Errorf("BankManager.Withdraw : Failed to authenticate account : AccountID=%d", accountID) + return fmt.Errorf("BankManager.Withdraw : Failed to authenticate account : AccountID=%d\n", request.AccountID) } // Deposit adiciona um valor ao saldo de uma conta especificada. -func (b *Bank) Deposit(accountID int64, accountPassword string, quantity float64, result *bool) error { - account, isAuthenticated := b.getAuthenticatedAccount(accountID, accountPassword) +func (b *Bank) Deposit(request FundsOperationRequest, result *bool) error { + account, isAuthenticated := b.getAuthenticatedAccount(request.AccountID, request.Password) if isAuthenticated { account.mutex.Lock() defer account.mutex.Unlock() - account.Balance += quantity + account.Balance += request.Quantity *result = true + fmt.Printf("BankManager.Deposit : Depositing on account : AccountID=%d : Balance=%.2f : Quantity=%.2f\n", request.AccountID, account.Balance, request.Quantity) return nil } *result = false - return fmt.Errorf("BankManager.Deposit : Failed to authenticate account : AccountID=%d", accountID) + fmt.Printf("BankManager.Deposit : Failed to authenticate account : AccountID=%d", request.AccountID) + return fmt.Errorf("BankManager.Deposit : Failed to authenticate account : AccountID=%d", request.AccountID) } // PeekBalance consulta o saldo de uma conta, se a senha estiver correta. -func (b *Bank) PeekBalance(accountID int64, accountPassword string, result *float64) error { - account, isAuthenticated := b.getAuthenticatedAccount(accountID, accountPassword) +func (b *Bank) PeekBalance(request AccountAccessRequest, result *float64) error { + account, isAuthenticated := b.getAuthenticatedAccount(request.AccountID, request.Password) if isAuthenticated { account.mutex.RLock() defer account.mutex.RUnlock() *result = account.Balance + + fmt.Printf("BankManager.PeekBalance : Peeking balance : AccountID=%d : Balance=%.2f\n", request.AccountID, account.Balance) return nil } - *result = 0 - return fmt.Errorf("BankManager.PeekBalance : Failed to authenticate account : AccountID=%d", accountID) + *result = -1 + fmt.Printf("BankManager.PeekBalance : Failed to authenticate account : AccountID=%d : AccountPassword=%s", request.AccountID, request.Password) + return fmt.Errorf("BankManager.PeekBalance : Failed to authenticate account : AccountID=%d", request.AccountID) } -func (b *Bank) getAuthenticatedAccount(accountID int64, accountPassword string) (*account, bool) { - account, accountExists := b.getAccount(accountID) +func (b *Bank) getAuthenticatedAccount(AccountID int, accountPassword string) (*account, bool) { + account, accountExists := b.getAccount(AccountID) if accountExists && (account.Password == accountPassword) { return account, true } @@ -140,10 +156,10 @@ func (b *Bank) getAuthenticatedAccount(accountID int64, accountPassword string) } // getAccount retorna uma conta segura e se ela existe. -func (b *Bank) getAccount(accountID int64) (*account, bool) { +func (b *Bank) getAccount(AccountID int) (*account, bool) { b.mutex.RLock() defer b.mutex.RUnlock() - info, exists := b.accounts[accountID] + info, exists := b.accounts[AccountID] return info, exists } diff --git a/src/Server/Server.go b/src/Server/Server.go index 9683a05..e3f3623 100644 --- a/src/Server/Server.go +++ b/src/Server/Server.go @@ -1,7 +1,8 @@ -package Server +package main import ( BankManager "Coinnect-FPPD/src/Server/Bank" + Pygmalion "Coinnect-FPPD/src/deps" "fmt" "net" "net/rpc" @@ -9,6 +10,19 @@ import ( var listener net.Listener +func main() { + fmt.Printf("Server.main : Initializing Operations") + // Carrega configurações + Pygmalion.InitConfigReader("settings.yml", ".") + port := Pygmalion.ReadInteger("ServerPort") + + // Inicia o servidor + Run(port) + // Garante que o servidor feche graciosamente :) + defer Close() + fmt.Printf("Server.main : Finishing Operations") +} + func Run(port int) { bank := new(BankManager.Bank) bank.Initialize() diff --git a/src/main.go b/src/main.go deleted file mode 100644 index 9c61255..0000000 --- a/src/main.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "Coinnect-FPPD/src/Client" - "Coinnect-FPPD/src/Menu" - "Coinnect-FPPD/src/Server" - Pygmalion "Coinnect-FPPD/src/deps" -) - -func main() { - // Carrega configurações - Pygmalion.InitConfigReader("settings.yml", ".") - port := Pygmalion.ReadInteger("ServerPort") - address := Pygmalion.ReadString("ServerAddr") - - // Inicia o servidor - go Server.Run(port) - // Garante que o servidor feche graciosamente :) - defer Server.Close() - - // Executa uma operação - callback := Menu.ObtainClientOperation() - - // Executa a chamada ao servidor - Client.SendOperation(address, port, callback) -}