Golang中的表达式语言支持

huangapple go评论87阅读模式
英文:

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 [&quot;good_customers&quot;, &quot;collaborator&quot;]

len(article.Comments) &gt; 100 and article.Category not in [&quot;misc&quot;]

product.Stock &lt; 15

all(Tickets, {.Price &gt;0})

And also has static type checker and user-friendly error messages

error: unclosed &quot;(&quot;
 | (boo + bar]
 | ----------^

huangapple
  • 本文由 发表于 2017年5月11日 04:26:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/43902155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定