I'm new to GO, so I wanted to try my hand in a little application to help me manage some trips. I'm following the design found here: sohamkamani.com
I'm encountering some errors that don't make sense to me...
src/trip-manager/handlers/PersonHandlers.go:14:40: not enough arguments in call to method expression stores.PersonStore.FindAll
have ()
want (stores.PersonStore)
My function doesn't want arguments? What am I missing here?
Also, I didn't encunter this error previously before splitting everything up in packages and before introducing a second store. But because I'm an idiot, I didn't make a commit back then to revert to, to find out what I've done wrong. hopefully someone here might spot my mistake?
handlers/PersonHandlers.go:14
var people, err = PersonStore.FindAll()
stores/PersonStore.go
type PersonStore interface {
FindAll() ([]*Person, error)
}
type DbPersonStore struct {
Db *sql.DB
}
var personStore PersonStore
func (personStore *DbPersonStore) FindAll() ([]*Person, error) {
...
}
func InitPersonStore(s PersonStore) {
personStore = s
}
And finally: main.go
func main() {
fmt.Println("Hello, world. Listening on port 3000")
router := NewRouter()
psqlInfo := fmt.Sprintf(
"host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
cred.Host, cred.Port, cred.User, cred.Password, cred.Database,
)
var db, err = sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
InitPersonStore(&DbPersonStore{Db: db})
log.Fatal(http.ListenAndServe(":3000", router))
}