Ola Estudante, tudo certo?
Primeiramente, obrigado pelo help!
Entáo, infelizmente eu conferi todos os pontos que vc mencionou e o problema persiste =s
Ao tentar rodar o go run eu reparei no erro package bank-go/accounts is not in std (/usr/local/go/src/bank-go/accounts)
Inclusive, tentei uma outra solucao com o comando "go work", mas sem sucesso
Deixa eu encaminhar o trecho do codigo por completo.
main.go
package main
import (
"bank-go/accounts"
"fmt"
)
func main() {
//How instance in a different way and atribute values
firstAccoutn := accounts.CurrentAccount{Owner: "Rafael", Balance: 100.5}
secondAccount := accounts.CurrentAccount{"Mariana", 111, 123456, 200.0}
firstAccoutn.agency = 123
fmt.Println(firstAccoutn)
fmt.Println(secondAccount)
//How intance in a third way, less usual in go
var thirdAccount *accounts.CurrentAccount
thirdAccount = new(accounts.CurrentAccount)
thirdAccount.Owner = "Guilherme"
fmt.Println(thirdAccount)
fmt.Println(*thirdAccount)
//Comparative exercise
var thirdAccount2 *accounts.CurrentAccount
thirdAccount2 = new(accounts.currCurrentAccountentAccount)
thirdAccount2.Owner = "Guilherme"
secondAccount2 := accounts.CurrentAccount{"Mariana", 111, 123456, 200.0}
fmt.Println(secondAccount == secondAccount2)
fmt.Println(thirdAccount == thirdAccount2)
fmt.Println(*thirdAccount == *thirdAccount2)
//Using the function withdraw
fourthAccount := accounts.CurrentAccount{Balance: 600}
fmt.Println(fourthAccount.withdraw(100))
fmt.Println(fourthAccount.Balance)
//Using function with more than 1 return
fifthAccount := accounts.CurrentAccount{Owner: "Giovanna", Balance: 300.0}
status, Balance := fifthAccount.deposit(500)
fmt.Println(status, Balance)
//Using transfer function
sixthAccount := accounts.CurrentAccount{Owner: "Paulo", Balance: 500.0}
seventhAccount := accounts.CurrentAccount{Owner: "Marcela", Balance: 600.0}
result := sixthAccount.transfer(400, &seventhAccount)
fmt.Println(result)
fmt.Println(sixthAccount)
fmt.Println(seventhAccount)
}
currentAccount.go
package accounts
// how create a struct
type CurrentAccount struct {
Owner string
Agency int
AccountNumber int
Balance float64
}
// Important to notice that you can use [c *currentAccount] to refer wich account are calling the method
func (c *CurrentAccount) withdraw(withdrawValue float64) string {
canWithdraw := withdrawValue > 0 && c.Balance >= withdrawValue
if canWithdraw {
c.Balance -= withdrawValue
return "Sucess Withdraw"
} else {
return "Failed Witthdraw"
}
}
func (c *CurrentAccount) deposit(depositValue float64) (string, float64) {
if depositValue > c.Balance {
c.Balance += depositValue
return "Sucess Deposit", c.Balance
} else {
return "Failed Deposit", c.Balance
}
}
func (c *CurrentAccount) transfer(transferValue float64, tranferAccount *CurrentAccount) bool {
if transferValue > 0 && transferValue < c.Balance {
c.Balance -= transferValue
tranferAccount.deposit(transferValue)
return true
} else {
return false
}
}
go.mod
module bank-go
go 1.21.2
go.work
go 1.21.2
use .