duancu4731 2013-08-04 02:28
浏览 252
已采纳

在go中使用函数作为if语句的参数

I'm trying to get the following to work:

func ArticlesHandler(w http.ResponseWriter, r *http.Request) {
  ...
  if(ValidTokenProvided(w,r)){
    ...
  }
  ...
}
func ValidTokenProvided(w http.ResponseWriter, r *http.Request) {
  ...
  return false
}

How can I pass a function as a parameter? or if I can't, what is the best way to achieve this.

  • 写回答

1条回答 默认 最新

  • duanbinren8906 2013-08-04 02:33
    关注

    ValidTokenProvided was a void method.. Made it bool:

    func ValidTokenProvided(w http.ResponseWriter, r *http.Request) bool {
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?