dtamho6404 2018-10-11 11:53
浏览 111
已采纳

没有参数的函数没有足够的参数

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))
}
  • 写回答

2条回答 默认 最新

  • drebew5059 2018-10-11 12:10
    关注
    handlers/PersonHandlers.go:14
    
    var people, err = PersonStore.FindAll()
    

    What you are doing is calling FindAll() on the interface instead of on an instance. You probably mistyped for the lowercase

    var people, err = personStore.FindAll()
    

    https://play.golang.org/p/nBc6tomURoa

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容