Dynamic SQL Query based on referenced URL variables...

agolangf · 2017-08-18 19:00:05 · 525 次点击    
这是一个分享于 2017-08-18 19:00:05 的资源,其中的信息可能已经有所发展或是发生改变。

What I'm trying to accomplish:

http://www.mysite.com/api?firstname=John&lastname=Smith

In the code, I need to dynamically generate a sql query based on the referenced URL variables (some or none could be specified... so it needs to be adaptive). To prevent SQL-injection, I need to structure the query in a way where the values of variables are appended to the '...interface{}' parameter of the db.Query() function (in the standard library).

This seems like an easy thing to do, but it isn't. If I could somehow convert a []interface{} that would satisfy the '...interface{}' (with the slice containing a pointer to the string holding the value) of the db.Query() call... that would work; however, I don't think that's possible. Any 3rd-party import or other advice on how to get what I'm needing going?


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

525 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传