dtx9763 2013-07-10 14:28 采纳率: 100%
浏览 121
已采纳

Golang动态绑定变量数

I've been working with MyMySQL and currently have written an API call that takes a variable number of parameters and generates a search query. I have been trying to bind the passed in parameters to protect against SQL injection, however I cannot seem to figure out how to handle a variable amount of parameters. The Bind function signature looks like:

Bind(params ...interface{})

Although I guessed both solutions wouldn't work, I tried binding each parameter one at a time in a loop, and then also tried passing in a []interface{} containing all of the parameter values.

Is there anyway to handle this solution? Struct binding wont work since I could have multiple values per each field. For instance, I could have 1 or 10 company IDs passed back to me.

  • 写回答

1条回答 默认 最新

  • dongliang2058 2013-07-10 14:45
    关注

    Your second attempt was close to success. Build a, say var foo []interface{} containing all arguments and pass it as

    Bind(foo...)
    

    See also Passing arguments to ... parameters

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效