英文:
Expression Language support in Golang
问题
我正在尝试实现一个功能,让用户可以在运行时尝试配置。
基本上,数据库中有一些预设配置,但用户可以在这些配置的基础上进行一些微调,并查看结果。
这个组件是用Golang编写的。我正在考虑一种方法,就是使用表达式语言支持。我找到了一些开源包,比如https://github.com/araddon/qlbridge。
但是几乎没有什么示例程序/教程演示如何在PostgresQL中使用表达式语言。
有人使用过并尝试过这样的东西吗?欢迎任何建议。谢谢你的时间!
英文:
I am trying to implement a functionality that lets users try out configurations in run rime.
Basically, there are some preexisting configurations in DB, but users can make some tweaks on top of those and see results.
This component is written in Golang. One approach i am thinking is about using expression language support. I found some open source packages like https://github.com/araddon/qlbridge
But there are almost negligible number of sample programs / tutorials that demo how to use expression language along with PostgresQL.
Has any one used and attempted such thing? Any suggestions are welcome. Thank you for your time!
答案1
得分: 3
尝试使用https://github.com/antonmedv/expr——这是一个可以评估表达式的引擎。
它可以处理像这样的表达式:
user.Group in ["good_customers", "collaborator"]
len(article.Comments) > 100 and article.Category not in ["misc"]
product.Stock < 15
all(Tickets, {.Price > 0})
它还具有静态类型检查器和用户友好的错误消息。
错误:未关闭的“(”
| (boo + bar]
| ----------^
英文:
Try https://github.com/antonmedv/expr – is an engine that can evaluate expressions.
It can handle expressions like this:
user.Group in ["good_customers", "collaborator"]
len(article.Comments) > 100 and article.Category not in ["misc"]
product.Stock < 15
all(Tickets, {.Price >0})
And also has static type checker and user-friendly error messages
error: unclosed "("
| (boo + bar]
| ----------^
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论